mirror of https://github.com/vuejs/core.git
65 lines
1.2 KiB
TypeScript
65 lines
1.2 KiB
TypeScript
import { defineCustomElement } from 'vue'
|
|
import { expectType, describe } from './utils'
|
|
|
|
describe('inject', () => {
|
|
// with object inject
|
|
defineCustomElement({
|
|
props: {
|
|
a: String
|
|
},
|
|
inject: {
|
|
foo: 'foo',
|
|
bar: 'bar'
|
|
},
|
|
created() {
|
|
expectType<unknown>(this.foo)
|
|
expectType<unknown>(this.bar)
|
|
// @ts-expect-error
|
|
this.foobar = 1
|
|
}
|
|
})
|
|
|
|
// with array inject
|
|
defineCustomElement({
|
|
props: ['a', 'b'],
|
|
inject: ['foo', 'bar'],
|
|
created() {
|
|
expectType<unknown>(this.foo)
|
|
expectType<unknown>(this.bar)
|
|
// @ts-expect-error
|
|
this.foobar = 1
|
|
}
|
|
})
|
|
|
|
// with no props
|
|
defineCustomElement({
|
|
inject: {
|
|
foo: {
|
|
from: 'pbar',
|
|
default: 'foo'
|
|
},
|
|
bar: {
|
|
from: 'pfoo',
|
|
default: 'bar'
|
|
}
|
|
},
|
|
created() {
|
|
expectType<unknown>(this.foo)
|
|
expectType<unknown>(this.bar)
|
|
// @ts-expect-error
|
|
this.foobar = 1
|
|
}
|
|
})
|
|
|
|
// without inject
|
|
defineCustomElement({
|
|
props: ['a', 'b'],
|
|
created() {
|
|
// @ts-expect-error
|
|
this.foo = 1
|
|
// @ts-expect-error
|
|
this.bar = 1
|
|
}
|
|
})
|
|
})
|