Skip to content

Commit

Permalink
fix(language-core): fallthrough attributes break component type when …
Browse files Browse the repository at this point in the history
…root tag type is unknown (#4729)
  • Loading branch information
johnsoncodehk authored Aug 27, 2024
1 parent 5a9bb12 commit 51bd930
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
17 changes: 12 additions & 5 deletions packages/language-core/lib/codegen/script/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,6 @@ export function* generatePropsOption(
const optionExpCodes: Code[] = [];
const typeOptionExpCodes: Code[] = [];

if (inheritAttrs && options.templateCodegen?.inheritedAttrVars.size && !hasEmitsOption) {
optionExpCodes.push(`{} as ${ctx.helperTypes.TypePropsToOption.name}<__VLS_PickNotAny<${ctx.helperTypes.OmitIndexSignature.name}<ReturnType<typeof __VLS_template>['attrs']>, {}>>`);
typeOptionExpCodes.push(`{} as ReturnType<typeof __VLS_template>['attrs']`);
}
if (ctx.generatedPropsType) {
optionExpCodes.push([
`{} as `,
Expand All @@ -141,11 +137,22 @@ export function* generatePropsOption(
].join(''));
typeOptionExpCodes.push(`{} as __VLS_PublicProps`);
}

if (scriptSetupRanges.props.define?.arg) {
const { arg } = scriptSetupRanges.props.define;
optionExpCodes.push(generateSfcBlockSection(scriptSetup, arg.start, arg.end, codeFeatures.navigation));
}
if (inheritAttrs && options.templateCodegen?.inheritedAttrVars.size && !hasEmitsOption) {
const attrsType = `ReturnType<typeof __VLS_template>['attrs']`;
const optionType = `${ctx.helperTypes.TypePropsToOption.name}<__VLS_PickNotAny<${ctx.helperTypes.OmitIndexSignature.name}<${attrsType}>, {}>>`;
if (optionExpCodes.length) {
optionExpCodes.unshift(`{} as ${optionType}`);
}
else {
// workaround for https://github.com/vuejs/core/pull/7419
optionExpCodes.unshift(`{} as keyof ${attrsType} extends never ? never: ${optionType}`);
}
typeOptionExpCodes.unshift(`{} as ${attrsType}`);
}

const useTypeOption = options.vueCompilerOptions.target >= 3.5 && typeOptionExpCodes.length;
const useOption = (!useTypeOption || scriptSetupRanges.props.withDefaults) && optionExpCodes.length;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script setup lang="ts">
declare const child: unknown;
</script>

<template>
<child />
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script setup lang="ts">
import basic from './basic.vue';
</script>

<template>
<basic />
</template>

0 comments on commit 51bd930

Please sign in to comment.