Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runtime-core): type refs and el backdoor issue for this type #12217

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions packages-private/dts-test/defineComponent.test-d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1804,6 +1804,35 @@ describe('__typeEmits backdoor, call signature syntax', () => {
c.$emit('update', 123)
})

describe('__typeRefs backdoor, for this type', () => {
type Refs = {
foo: number
}
defineComponent({
__typeRefs: {} as { child: ComponentInstance<typeof Child> },
mounted() {
expectType<ComponentInstance<typeof Child>>(this.$refs.child)
},
})
const Child = defineComponent({
__typeRefs: {} as Refs,
methods: {
test() {
expectType<number>(this.$refs.foo)
},
},
})
})

describe('__typeEl backdoor, for this type', () => {
defineComponent({
__typeEl: {} as HTMLAnchorElement,
mounted() {
expectType<HTMLAnchorElement>(this.$el)
},
})
})

describe('__typeRefs backdoor, object syntax', () => {
type Refs = {
foo: number
Expand Down
4 changes: 3 additions & 1 deletion packages/runtime-core/src/apiDefineComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,9 @@ export function defineComponent<
Slots,
LocalComponents,
Directives,
Exposed
Exposed,
TypeRefs,
TypeEl
>
>,
): DefineComponent<
Expand Down