Skip to content

Commit

Permalink
fix(tsc): TS4082 not reported for functional component
Browse files Browse the repository at this point in the history
close #4569
  • Loading branch information
johnsoncodehk committed Jul 22, 2024
1 parent c0ec60a commit bc8521e
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 2 deletions.
14 changes: 13 additions & 1 deletion packages/language-core/lib/codegen/script/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,19 @@ export function* generateScript(options: ScriptCodegenOptions): Generator<Code>
yield* generateDefineProp(options, options.sfc.scriptSetup);
yield* generateScriptSetup(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
}
yield endOfLine;

yield `;`;
if (options.sfc.scriptSetup) {
// #4569
yield [
'',
'scriptSetup',
options.sfc.scriptSetup.content.length,
codeFeatures.verification,
];
}
yield newLine;

if (options.globalTypes) {
yield generateGlobalTypes(options.vueCompilerOptions);
}
Expand Down
9 changes: 9 additions & 0 deletions packages/language-core/lib/codegen/script/scriptSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ export function* generateScriptSetup(

if (scriptSetup.generic) {
if (!options.scriptRanges?.exportDefault) {
if (options.sfc.scriptSetup) {
// #4569
yield [
'',
'scriptSetup',
options.sfc.scriptSetup.content.length,
codeFeatures.verification,
];
}
yield `export default `;
}
yield `(<`;
Expand Down
3 changes: 2 additions & 1 deletion packages/tsc/tests/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const shouldErrorDirs = [
'should-error',
'should-error-2',
'should-error-3',
'should-error-#4569',
];

function prettyPath(path: string, isRoot: boolean) {
Expand Down Expand Up @@ -52,7 +53,7 @@ function runVueTsc(cwd: string) {
return new Promise((resolve, reject) => {
const cp = fork(
binPath,
['--noEmit'],
[],
{
silent: true,
cwd
Expand Down
7 changes: 7 additions & 0 deletions test-workspace/tsc/should-error-#4569/main.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script lang="ts" setup generic="TItem">
interface Props {
item: any;
}
defineProps<Props>();
</script>
9 changes: 9 additions & 0 deletions test-workspace/tsc/should-error-#4569/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"include": [ "**/*" ],
"compilerOptions": {
"noEmit": false,
"emitDeclarationOnly": true,
"declaration": true,
}
}
1 change: 1 addition & 0 deletions test-workspace/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"noUnusedParameters": true,
"skipLibCheck": true,
"allowJs": true,
"noEmit": true,
"jsx": "preserve",
"baseUrl": ".",
},
Expand Down

0 comments on commit bc8521e

Please sign in to comment.