From a3b3bad365bb1933ee9700e74e7d61625ae3fb09 Mon Sep 17 00:00:00 2001 From: Misha Kaletsky Date: Sat, 29 Jan 2022 15:57:48 -0500 Subject: [PATCH 1/4] Switch to expect-type See https://github.com/sindresorhus/dot-prop/issues/84 and https://github.com/SamVerschueren/tsd/issues/142 --- index.test-d.ts | 20 ++++++++++---------- package.json | 7 ++++--- tsconfig.json | 8 ++++++++ 3 files changed, 22 insertions(+), 13 deletions(-) create mode 100644 tsconfig.json diff --git a/index.test-d.ts b/index.test-d.ts index d33e872..1462f06 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,18 +1,18 @@ -import {expectType, expectAssignable} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import {getProperty, setProperty, hasProperty, deleteProperty} from './index.js'; -expectType(getProperty({foo: {bar: 'unicorn'}}, 'foo.bar')); -expectType(getProperty({foo: {bar: 'a'}}, 'foo.notDefined.deep')); -expectAssignable( +expectTypeOf(getProperty({foo: {bar: 'unicorn'}}, 'foo.bar')).toBeString(); +expectTypeOf(getProperty({foo: {bar: 'a'}}, 'foo.notDefined.deep')).toBeUndefined(); +expectTypeOf( getProperty({foo: {bar: 'a'}}, 'foo.notDefined.deep', 'default value'), -); -expectType( +).toBeString(); +expectTypeOf( getProperty({foo: {'dot.dot': 'unicorn'}}, 'foo.dot\\.dot'), -); +).toEqualTypeOf(); const object = {foo: {bar: 'a'}}; -expectType(setProperty(object, 'foo.bar', 'b')); +expectTypeOf(setProperty(object, 'foo.bar', 'b')).toEqualTypeOf(object); -expectType(hasProperty({foo: {bar: 'unicorn'}}, 'foo.bar')); +expectTypeOf(hasProperty({foo: {bar: 'unicorn'}}, 'foo.bar')).toEqualTypeOf(); -expectType(deleteProperty({foo: {bar: 'a'}}, 'foo.bar')); +expectTypeOf(deleteProperty({foo: {bar: 'a'}}, 'foo.bar')).toEqualTypeOf(); diff --git a/package.json b/package.json index 697cc4b..350a4dc 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "node": "^12.20.0 || ^14.13.1 || >=16.0.0" }, "scripts": { - "test": "xo && ava && tsd", + "test": "xo && ava && tsc", "bench": "node benchmark.js" }, "files": [ @@ -42,7 +42,8 @@ "devDependencies": { "ava": "^4.0.1", "benchmark": "^2.1.4", - "tsd": "^0.19.1", + "expect-type": "^0.13.0", + "typescript": "^4.5.5", "xo": "^0.47.0" } -} +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..d1edbb2 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "lib": ["es2020"], + "strict": true, + "noEmit": true + }, + "include": ["*.ts"] +} From 65ee3bed2efacf9ef4b0e1495e5bf5802ca301ff Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Tue, 15 Feb 2022 17:44:50 +0700 Subject: [PATCH 2/4] Update tsconfig.json --- tsconfig.json | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tsconfig.json b/tsconfig.json index d1edbb2..0c9966a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,8 +1,12 @@ { - "compilerOptions": { - "lib": ["es2020"], - "strict": true, - "noEmit": true - }, - "include": ["*.ts"] + "compilerOptions": { + "lib": [ + "es2020" + ], + "strict": true, + "noEmit": true + }, + "include": [ + "*.ts" + ] } From 9fda35d028bf39c15aea5413a459f063416defac Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Tue, 15 Feb 2022 17:45:01 +0700 Subject: [PATCH 3/4] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 350a4dc..bb3b97a 100644 --- a/package.json +++ b/package.json @@ -46,4 +46,4 @@ "typescript": "^4.5.5", "xo": "^0.47.0" } -} \ No newline at end of file +} From a26ee1055e160666cffa10926f0cca862617cc16 Mon Sep 17 00:00:00 2001 From: Misha Kaletsky Date: Tue, 15 Feb 2022 08:26:42 -0500 Subject: [PATCH 4/4] Fix the bug --- index.d.ts | 2 +- index.test-d.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 843f8f9..f812a4c 100644 --- a/index.d.ts +++ b/index.d.ts @@ -31,7 +31,7 @@ export function getProperty | unknown[] ? (Get extends unknown ? DefaultValue : Get) : undefined; +): ObjectType extends Record | unknown[] ? (unknown extends Get ? DefaultValue : Get) : undefined; /** Set the property at the given path to the given value. diff --git a/index.test-d.ts b/index.test-d.ts index 1462f06..53d859c 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -8,6 +8,7 @@ expectTypeOf( ).toBeString(); expectTypeOf( getProperty({foo: {'dot.dot': 'unicorn'}}, 'foo.dot\\.dot'), + // @ts-expect-error type-fest's `Get` not smart enough to deal with escaped dots ).toEqualTypeOf(); const object = {foo: {bar: 'a'}};