diff --git a/packages/dts-test/defineComponent.test-d.tsx b/packages/dts-test/defineComponent.test-d.tsx index 0d2e35d7983..a5978b65194 100644 --- a/packages/dts-test/defineComponent.test-d.tsx +++ b/packages/dts-test/defineComponent.test-d.tsx @@ -475,6 +475,26 @@ describe('type inference w/ options API', () => { }) }) +// #4051 +describe('type inference w/ empty prop object', () => { + const MyComponent = defineComponent({ + props: {}, + setup(props) { + return {} + }, + render() {} + }) + expectType() + // AllowedComponentProps + expectType() + // ComponentCustomProps + expectType() + // VNodeProps + expectType() + // @ts-expect-error + expectError() +}) + describe('with mixins', () => { const MixinA = defineComponent({ emits: ['bar'], @@ -1040,7 +1060,7 @@ describe('inject', () => { expectType(this.foo) expectType(this.bar) // @ts-expect-error - this.foobar = 1 + expectError((this.foobar = 1)) } }) @@ -1052,7 +1072,7 @@ describe('inject', () => { expectType(this.foo) expectType(this.bar) // @ts-expect-error - this.foobar = 1 + expectError((this.foobar = 1)) } }) @@ -1072,7 +1092,7 @@ describe('inject', () => { expectType(this.foo) expectType(this.bar) // @ts-expect-error - this.foobar = 1 + expectError((this.foobar = 1)) } }) @@ -1081,9 +1101,9 @@ describe('inject', () => { props: ['a', 'b'], created() { // @ts-expect-error - this.foo = 1 + expectError((this.foo = 1)) // @ts-expect-error - this.bar = 1 + expectError((this.bar = 1)) } }) }) diff --git a/packages/runtime-core/src/apiDefineComponent.ts b/packages/runtime-core/src/apiDefineComponent.ts index c10ac74e4a9..1f858ccc8fb 100644 --- a/packages/runtime-core/src/apiDefineComponent.ts +++ b/packages/runtime-core/src/apiDefineComponent.ts @@ -170,9 +170,9 @@ export function defineComponent< export function defineComponent< // the Readonly constraint allows TS to treat the type of { required: true } // as constant instead of boolean. - PropsOptions extends Readonly, - RawBindings, - D, + PropsOptions extends Readonly = {}, + RawBindings = {}, + D = {}, C extends ComputedOptions = {}, M extends MethodOptions = {}, Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,