-return { }
-}
-
-})"
-`;
-
-exports[`defineProps > w/ TSTypeAliasDeclaration 1`] = `
-"import { defineComponent as _defineComponent } from 'vue'
-type FunFoo<O> = (item: O) => boolean;
- type FunBar = FunFoo<number>;
-
-export default /*@__PURE__*/_defineComponent({
- props: {
- foo: { type: Function, required: false, default: () => true },
- bar: { type: Function, required: false, default: () => true }
- },
- setup(__props: any, { expose: __expose }) {
- __expose();
-
-
-
return { }
}
expect(content).toMatch(`foo: { default: 5.5, type: Number }`)
assertCode(content)
})
-
- test('w/ TSTypeAliasDeclaration', () => {
- const { content } = compile(`
- <script setup lang="ts">
- type FunFoo<O> = (item: O) => boolean;
- type FunBar = FunFoo<number>;
- withDefaults(
- defineProps<{
- foo?: FunFoo<number>;
- bar?: FunBar;
- }>(),
- {
- foo: () => true,
- bar: () => true,
- },
- );
- </script>
- `)
- assertCode(content)
- expect(content).toMatch(
- `foo: { type: Function, required: false, default: () => true }`,
- )
- expect(content).toMatch(
- `bar: { type: Function, required: false, default: () => true }`,
- )
- })
})
})
})
+ describe('type alias declaration', () => {
+ // #13240
+ test('function type', () => {
+ expect(
+ resolve(`
+ type FunFoo<O> = (item: O) => boolean;
+ type FunBar = FunFoo<number>;
+ defineProps<{
+ foo?: FunFoo<number>;
+ bar?: FunBar;
+ }>()
+ `).props,
+ ).toStrictEqual({
+ foo: ['Function'],
+ bar: ['Function'],
+ })
+ })
+
+ test('fallback to Unknown', () => {
+ expect(
+ resolve(`
+ type Brand<T> = T & {};
+ defineProps<{
+ foo: Brand<string>;
+ }>()
+ `).props,
+ ).toStrictEqual({
+ foo: [UNKNOWN_TYPE],
+ })
+ })
+ })
+
describe('generics', () => {
test('generic with type literal', () => {
expect(
case 'TSTypeReference': {
const resolved = resolveTypeReference(ctx, node, scope)
if (resolved) {
- if (resolved.type === 'TSTypeAliasDeclaration') {
- return inferRuntimeType(
- ctx,
- resolved.typeAnnotation,
- resolved._ownerScope,
- isKeyOf,
- )
+ // #13240
+ // Special case for function type aliases to ensure correct runtime behavior
+ // other type aliases still fallback to unknown as before
+ if (
+ resolved.type === 'TSTypeAliasDeclaration' &&
+ resolved.typeAnnotation.type === 'TSFunctionType'
+ ) {
+ return ['Function']
}
return inferRuntimeType(ctx, resolved, resolved._ownerScope, isKeyOf)
}