From 344466a8fd4b805b58fb9087f1aacd017f3f362d Mon Sep 17 00:00:00 2001 From: Ilya Golovin Date: Wed, 1 Nov 2023 00:08:59 +0300 Subject: [PATCH 1/3] fix: `defineComponent` type no prop suggestions --- types/test/v3/define-component-test.js | 23 +++++++++++++++++++++++ types/tsconfig.json | 2 ++ types/v3-define-component.d.ts | 2 +- 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 types/test/v3/define-component-test.js diff --git a/types/test/v3/define-component-test.js b/types/test/v3/define-component-test.js new file mode 100644 index 00000000000..9cacad6d4a2 --- /dev/null +++ b/types/test/v3/define-component-test.js @@ -0,0 +1,23 @@ +// @ts-check +import { defineComponent } from '../../index' +import { expectError, expectType, describe } from '../utils' +const props = { + a: Number +} +describe('defineComponents works in js', () => { + defineComponent({ + props, + computed: { + test() { + /** @type import('../utils').IsAny */ + let test + + // @ts-expect-error + expectType(/** @type {number | undefined} */ (test)) + + // @ts-expect-error + expectError(this.b) + } + } + }) +}) diff --git a/types/tsconfig.json b/types/tsconfig.json index 36c5afee057..8842b3e6a22 100644 --- a/types/tsconfig.json +++ b/types/tsconfig.json @@ -5,6 +5,7 @@ "lib": ["dom", "esnext"], "types": ["node"], "module": "esnext", + "allowJs": true, "moduleResolution": "node", "jsx": "preserve", "strict": true, @@ -14,5 +15,6 @@ } }, "include": ["."], + "files": ["./test/v3/define-component-test.js"], "compileOnSave": false } diff --git a/types/v3-define-component.d.ts b/types/v3-define-component.d.ts index 03ef52d1856..257ede3a07a 100644 --- a/types/v3-define-component.d.ts +++ b/types/v3-define-component.d.ts @@ -139,7 +139,7 @@ export function defineComponent< * see `ExtractPropTypes` in './componentProps.ts' */ export function defineComponent< - Props, + Props = unknown, RawBindings = {}, D = {}, C extends ComputedOptions = {}, From 3f70f1bc7f4dbff86e4582eeb7c4081d783552be Mon Sep 17 00:00:00 2001 From: Ilya Golovin Date: Wed, 1 Nov 2023 11:37:27 +0300 Subject: [PATCH 2/3] fix: better test --- types/test/v3/define-component-test.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/types/test/v3/define-component-test.js b/types/test/v3/define-component-test.js index 9cacad6d4a2..3ac4f59e622 100644 --- a/types/test/v3/define-component-test.js +++ b/types/test/v3/define-component-test.js @@ -1,6 +1,6 @@ // @ts-check import { defineComponent } from '../../index' -import { expectError, expectType, describe } from '../utils' +import { expectError, describe } from '../utils' const props = { a: Number } @@ -9,13 +9,10 @@ describe('defineComponents works in js', () => { props, computed: { test() { - /** @type import('../utils').IsAny */ - let test + // @ts-expect-error Invalid typecast if `this.a` is not any + ;/** @type import('../utils').IsAny */ (this.a) - // @ts-expect-error - expectType(/** @type {number | undefined} */ (test)) - - // @ts-expect-error + // @ts-expect-error Unknown property expectError(this.b) } } From e509aebe8e8d4ff743bfa63826db1e1aec4f967f Mon Sep 17 00:00:00 2001 From: Ilya Golovin Date: Wed, 1 Nov 2023 11:59:32 +0300 Subject: [PATCH 3/3] fix: typo --- types/test/v3/define-component-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/test/v3/define-component-test.js b/types/test/v3/define-component-test.js index 3ac4f59e622..868e862c24d 100644 --- a/types/test/v3/define-component-test.js +++ b/types/test/v3/define-component-test.js @@ -4,7 +4,7 @@ import { expectError, describe } from '../utils' const props = { a: Number } -describe('defineComponents works in js', () => { +describe('defineComponent prop types work in js', () => { defineComponent({ props, computed: {