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: avoid losing generic types #3565

Merged
merged 17 commits into from
Sep 19, 2023
5 changes: 3 additions & 2 deletions packages/vue-language-core/src/generators/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ export function generate(

codes.push(
`type ${var_componentPropsInstance}_props = NonNullable<NonNullable<typeof ${var_componentPropsInstance}.__ctx>['props']>;\n`,
`type ${var_componentInstance}_propsType = __VLS_MappedOmit<Parameters<typeof ${var_functionalComponent}>[0], (__VLS_IsAny<${var_componentPropsInstance}_props> extends true ? never : keyof ${var_componentPropsInstance}_props) | keyof JSX.ElementChildrenAttribute> & __VLS_MappedOmit<__VLS_PickNotAny<${var_componentPropsInstance}_props, {}>, keyof JSX.ElementChildrenAttribute>;\n`,
`type ${var_componentInstance}_propsType = __VLS_MappedOmit<Parameters<typeof ${var_functionalComponent}>[0], (__VLS_IsAny<${var_componentPropsInstance}_props> extends true ? never : keyof ${var_componentPropsInstance}_props) | keyof JSX.ElementChildrenAttribute> & __VLS_MappedOmit<__VLS_PickNotAny<${var_componentPropsInstance}_props, {}>, keyof JSX.ElementChildrenAttribute> & Record<string, unknown>;\n`,
);
}

Expand All @@ -759,10 +759,11 @@ export function generate(
tagOffsets.length ? ['', 'template', tagOffsets[0], capabilitiesPresets.diagnosticOnly]
: dynamicTagExp ? ['', 'template', startTagOffset, capabilitiesPresets.diagnosticOnly]
: '',
vueCompilerOptions.strictTemplates ? '' : `__VLS_cast<__VLS_Prettify<${var_componentInstance}_propsType>>(`,
'{ ',
...createPropsCode(node, props, 'normal', propsFailedExps),
`}`,
vueCompilerOptions.strictTemplates ? '' : ` as ${var_componentInstance}_propsType`,
vueCompilerOptions.strictTemplates ? '' : `)`,
// diagnostic end
tagOffsets.length ? ['', 'template', tagOffsets[0] + tag.length, capabilitiesPresets.diagnosticOnly]
: dynamicTagExp ? ['', 'template', startTagOffset + tag.length, capabilitiesPresets.diagnosticOnly]
Expand Down
2 changes: 2 additions & 0 deletions packages/vue-language-core/src/utils/globalTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ declare function __VLS_componentProps<T, K>(comp: T, fnReturn: K):
__VLS_PickNotAny<K, {}> extends { __ctx: { props: infer P } } ? NonNullable<P>
: T extends (props: infer P, ...args: any) => any ? NonNullable<P> :
{};

declare function __VLS_cast<T>(x: T): T;
johnsoncodehk marked this conversation as resolved.
Show resolved Hide resolved
`.trim();
}

Expand Down