mirror of
https://github.com/vuejs/vue.git
synced 2024-11-21 20:28:54 +00:00
fix(types): fix missing error for accessing undefined instance properties
fix #12718
This commit is contained in:
parent
7161176cd0
commit
8521f9d3f6
@ -1166,6 +1166,62 @@ defineComponent({
|
||||
}
|
||||
})
|
||||
|
||||
describe('constructor attach custom properties', () => {
|
||||
// #12742 allow attaching custom properties (consistent with v3)
|
||||
const Foo = defineComponent({})
|
||||
Foo.foobar = 123
|
||||
})
|
||||
|
||||
describe('constructor instance type', () => {
|
||||
const Comp = defineComponent({
|
||||
data() {
|
||||
return {
|
||||
a: 1
|
||||
}
|
||||
},
|
||||
|
||||
computed: {
|
||||
ac() {
|
||||
return 1
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
callA(b: number) {
|
||||
return b
|
||||
}
|
||||
},
|
||||
|
||||
setup() {
|
||||
return {
|
||||
sa: '1'
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const comp = new Comp()
|
||||
|
||||
expectType<number>(comp.a)
|
||||
expectType<number>(comp.ac)
|
||||
expectType<string>(comp.sa)
|
||||
expectType<(b: number) => number>(comp.callA)
|
||||
})
|
||||
|
||||
describe('should report non-existent properties in instance', () => {
|
||||
const Foo = defineComponent({})
|
||||
const instance = new Foo()
|
||||
// @ts-expect-error
|
||||
instance.foo
|
||||
|
||||
const Foo2 = defineComponent({
|
||||
data() {
|
||||
return {}
|
||||
},
|
||||
methods: {
|
||||
example() {}
|
||||
}
|
||||
})
|
||||
const instance2 = new Foo2()
|
||||
// @ts-expect-error
|
||||
instance2.foo
|
||||
})
|
||||
|
10
types/v3-define-component.d.ts
vendored
10
types/v3-define-component.d.ts
vendored
@ -72,7 +72,7 @@ export type DefineComponent<
|
||||
*/
|
||||
export function defineComponent<
|
||||
RawBindings,
|
||||
D = Data,
|
||||
D = {},
|
||||
C extends ComputedOptions = {},
|
||||
M extends MethodOptions = {},
|
||||
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
|
||||
@ -101,8 +101,8 @@ export function defineComponent<
|
||||
*/
|
||||
export function defineComponent<
|
||||
PropNames extends string,
|
||||
RawBindings = Data,
|
||||
D = Data,
|
||||
RawBindings = {},
|
||||
D = {},
|
||||
C extends ComputedOptions = {},
|
||||
M extends MethodOptions = {},
|
||||
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
|
||||
@ -140,8 +140,8 @@ export function defineComponent<
|
||||
*/
|
||||
export function defineComponent<
|
||||
Props,
|
||||
RawBindings = Data,
|
||||
D = Data,
|
||||
RawBindings = {},
|
||||
D = {},
|
||||
C extends ComputedOptions = {},
|
||||
M extends MethodOptions = {},
|
||||
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
|
||||
|
Loading…
Reference in New Issue
Block a user