Skip to content

fix(compiler-sfc): genSetupPropsType #6179

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

Closed
wants to merge 1 commit into from
Closed
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
15 changes: 8 additions & 7 deletions packages/compiler-sfc/src/compileScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ export function compileScript(
let propsDestructureRestId: string | undefined
let propsTypeDecl: TSTypeLiteral | TSInterfaceBody | undefined
let propsTypeDeclRaw: Node | undefined
let propsTypeDeclInScript = false
let propsIdentifier: string | undefined
let emitsRuntimeDecl: Node | undefined
let emitsTypeDecl:
Expand Down Expand Up @@ -405,10 +406,10 @@ export function compileScript(
}

propsTypeDeclRaw = node.typeParameters.params[0]
propsTypeDecl = resolveQualifiedType(
;[propsTypeDecl, propsTypeDeclInScript] = resolveQualifiedType(
propsTypeDeclRaw,
node => node.type === 'TSTypeLiteral'
) as TSTypeLiteral | TSInterfaceBody | undefined
) as [TSTypeLiteral | TSInterfaceBody | undefined, boolean]

if (!propsTypeDecl) {
error(
Expand Down Expand Up @@ -532,10 +533,10 @@ export function compileScript(
}

emitsTypeDeclRaw = node.typeParameters.params[0]
emitsTypeDecl = resolveQualifiedType(
;[emitsTypeDecl] = resolveQualifiedType(
emitsTypeDeclRaw,
node => node.type === 'TSFunctionType' || node.type === 'TSTypeLiteral'
) as TSFunctionType | TSTypeLiteral | TSInterfaceBody | undefined
) as [TSFunctionType | TSTypeLiteral | TSInterfaceBody | undefined, boolean]

if (!emitsTypeDecl) {
error(
Expand All @@ -558,7 +559,7 @@ export function compileScript(
qualifier: (node: Node) => boolean
) {
if (qualifier(node)) {
return node
return [node, false]
}
if (
node.type === 'TSTypeReference' &&
Expand Down Expand Up @@ -587,7 +588,7 @@ export function compileScript(
for (const node of body) {
const qualified = isQualifiedType(node)
if (qualified) {
return qualified
return [qualified, !scriptSetupAst.body.includes(node)]
}
}
}
Expand Down Expand Up @@ -767,7 +768,7 @@ export function compileScript(
}

function genSetupPropsType(node: TSTypeLiteral | TSInterfaceBody) {
const scriptSetupSource = scriptSetup!.content
const scriptSetupSource = (!propsTypeDeclInScript ? scriptSetup : script)!.content
if (hasStaticWithDefaults()) {
// if withDefaults() is used, we need to remove the optional flags
// on props that have default values
Expand Down