Skip to content

Commit

Permalink
fix(compiler-sfc): correctly resolve type annotation for declared fun…
Browse files Browse the repository at this point in the history
…ction (#11279)

close #11266
  • Loading branch information
lzl0304 authored Jul 17, 2024
1 parent 3dc5a1a commit b287aee
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,26 @@ describe('resolveType', () => {
})
})

// #11266
test('correctly parse type annotation for declared function', () => {
const { props } = resolve(`
import { ExtractPropTypes } from 'vue'
interface UploadFile<T = any> {
xhr?: T
}
declare function uploadProps<T = any>(): {
fileList: {
type: PropType<UploadFile<T>[]>
default: UploadFile<T>[]
}
}
type UploadProps = ExtractPropTypes<ReturnType<typeof uploadProps>>
defineProps<UploadProps>()`)
expect(props).toStrictEqual({
fileList: ['Array'],
})
})

describe('generics', () => {
test('generic with type literal', () => {
expect(
Expand Down
1 change: 1 addition & 0 deletions packages/compiler-sfc/src/script/resolveType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ function innerResolveTypeElements(
case 'TSInterfaceDeclaration':
return resolveInterfaceMembers(ctx, node, scope, typeParameters)
case 'TSTypeAliasDeclaration':
case 'TSTypeAnnotation':
case 'TSParenthesizedType':
return resolveTypeElements(
ctx,
Expand Down

0 comments on commit b287aee

Please sign in to comment.