Skip to content

Commit 6201b84

Browse files
committed
feat: support native element
1 parent 6e97d23 commit 6201b84

File tree

4 files changed

+25
-14
lines changed

4 files changed

+25
-14
lines changed

packages/language-core/lib/codegen/globalTypes.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,20 @@ export function generateGlobalTypes(lib: string, target: number, strictTemplates
5757
? K extends { __ctx?: { props?: infer P } } ? NonNullable<P> : never
5858
: T extends (props: infer P, ...args: any) => any ? P
5959
: {};
60+
type __VLS_FunctionalGeneralComponent<T> = (props: ${fnPropsType}, ctx?: any) => __VLS_Element & {
61+
__ctx?: {
62+
attrs?: any,
63+
slots?: T extends { ${getSlotsPropertyName(target)}: infer Slots } ? Slots : any,
64+
emit?: T extends { $emit: infer Emit } ? Emit : any,
65+
props?: ${fnPropsType},
66+
expose?(exposed: T): void,
67+
}
68+
};
69+
type __VLS_NormalizeSlotReturns<S, R = ReturnType<NonNullable<S>>> = R extends any[] ? {
70+
[K in keyof R]: R[K] extends { __ctx?: any } | Element
71+
? R[K]
72+
: ReturnType<__VLS_FunctionalGeneralComponent<R[K]>>
73+
} : R;
6074
type __VLS_IsFunction<T, K> = K extends keyof T
6175
? __VLS_IsAny<T[K]> extends false
6276
? unknown extends T[K]
@@ -99,19 +113,6 @@ export function generateGlobalTypes(lib: string, target: number, strictTemplates
99113
type __VLS_PrettifyGlobal<T> = { [K in keyof T]: T[K]; } & {};
100114
type __VLS_UseTemplateRef<T> = Readonly<import('${lib}').ShallowRef<T | null>>;
101115
102-
type __VLS_FunctionalGeneralComponent<T> = (props: ${fnPropsType}, ctx?: any) => __VLS_Element & {
103-
__ctx?: {
104-
attrs?: any,
105-
slots?: T extends { ${getSlotsPropertyName(target)}: infer Slots } ? Slots : any,
106-
emit?: T extends { $emit: infer Emit } ? Emit : any,
107-
props?: ${fnPropsType},
108-
expose?(exposed: T): void,
109-
}
110-
};
111-
type __VLS_NormalizeSlotReturns<S, R = ReturnType<NonNullable<S>>> = R extends any[] ? {
112-
[K in keyof R]: R[K] extends { __ctx?: any } ? R[K] : ReturnType<__VLS_FunctionalGeneralComponent<R[K]>>
113-
} : R;
114-
115116
function __VLS_getVForSourceType(source: number): [number, number, number][];
116117
function __VLS_getVForSourceType(source: string): [string, number, number][];
117118
function __VLS_getVForSourceType<T extends any[]>(source: T): [

packages/language-core/lib/codegen/template/element.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,12 @@ export function* generateElement(
307307
: undefined;
308308
const failedPropExps: FailedPropExpression[] = [];
309309

310+
ctx.currentComponent?.childNodes.push({
311+
name: `__VLS_nativeElements.${node.tag}`,
312+
start: node.loc.start.offset,
313+
end: node.loc.end.offset
314+
});
315+
310316
yield `__VLS_asFunctionalElement(__VLS_intrinsicElements`;
311317
yield* generatePropertyAccess(
312318
options,

test-workspace/tsc/passedFixtures/vue3/slot-children/main.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,9 @@ const foo = {} as 'a' | 'b';
1111
<Child :foo="(`b` as const)" />
1212
<!-- @vue-expect-error -->
1313
<Child :foo="(`c` as const)" />
14+
15+
<a></a>
16+
<!-- @vue-expect-error -->
17+
<img />
1418
</Parent>
1519
</template>

test-workspace/tsc/passedFixtures/vue3/slot-children/parent.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ defineProps<{
55
foo: T;
66
}>();
77
defineSlots<{
8-
default?(): ReturnType<typeof Child<T>>[];
8+
default?(): (ReturnType<typeof Child<T>> | HTMLAnchorElement)[];
99
}>();
1010
</script>

0 commit comments

Comments
 (0)