-
-
Notifications
You must be signed in to change notification settings - Fork 124
Closed
Description
"Expected" comes from the usage example in the readme and "Actual" comes from typescript's intellisense in VS Code.
The main thing I noticed is the setter and deleter don't seem to mutate the type.
I'm using v6.0.1 of dot-prop with typescript v4.2.4.
import dotProp from 'dot-prop';
{
// Getter
dotProp.get({foo: {bar: 'unicorn'}}, 'foo.bar');
// Expected => 'unicorn'
// Actual => unknown
dotProp.get({foo: {bar: 'a'}}, 'foo.notDefined.deep');
// Expected => undefined
// Actual => unknown
dotProp.get({foo: {bar: 'a'}}, 'foo.notDefined.deep', 'default value');
// Expected => 'default value'
// Actual => 'default value'
dotProp.get({foo: {'dot.dot': 'unicorn'}}, 'foo.dot\\.dot');
// Expected => 'unicorn'
// Actual => unknown
}
{
// Setter
const object = {foo: {bar: 'a'}};
dotProp.set(object, 'foo.bar', 'b');
console.log(object);
// Expected => { foo: { bar: 'b' } }
// Actual => { foo: { bar: string; }; }
const foo = dotProp.set({}, 'foo.bar', 'c');
console.log(foo);
// Expected => {foo: {bar: 'c'}}
// Actual => const foo: {}
dotProp.set(object, 'foo.baz', 'x');
console.log(object);
// Expected => {foo: {bar: 'b', baz: 'x'}}
// Actual => const object: { foo: { bar: string; }; }
// Has
dotProp.has({foo: {bar: 'unicorn'}}, 'foo.bar');
// Expected => true
// Actual => boolean
}
{
// Deleter
const object = {foo: {bar: 'a'}};
dotProp.delete(object, 'foo.bar');
console.log(object);
// Expected => {foo: {}}
// Actual => const object: { foo: { bar: string; }; }
object.foo.bar = {x: 'y', y: 'x'};
// Type '{ x: string; y: string; }' is not assignable to type 'string'.ts(2322)
dotProp.delete(object, 'foo.bar.x');
console.log(object);
// Expected => {foo: {bar: {y: 'x'}}}
// Actual => const object: { foo: { bar: string; }; }
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels