|
@@ -74,6 +74,7 @@ export type SimpleTypeResolveContext = Pick<
|
|
|
|
|
|
|
|
// utils
|
|
// utils
|
|
|
| 'error'
|
|
| 'error'
|
|
|
|
|
+ | 'warn'
|
|
|
| 'helper'
|
|
| 'helper'
|
|
|
| 'getString'
|
|
| 'getString'
|
|
|
|
|
|
|
@@ -95,7 +96,12 @@ export type SimpleTypeResolveContext = Pick<
|
|
|
options: SimpleTypeResolveOptions
|
|
options: SimpleTypeResolveOptions
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-export type TypeResolveContext = ScriptCompileContext | SimpleTypeResolveContext
|
|
|
|
|
|
|
+export type TypeResolveContext = (
|
|
|
|
|
+ | ScriptCompileContext
|
|
|
|
|
+ | SimpleTypeResolveContext
|
|
|
|
|
+) & {
|
|
|
|
|
+ silentOnExtendsFailure?: boolean
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
type Import = Pick<ImportBinding, 'source' | 'imported'>
|
|
type Import = Pick<ImportBinding, 'source' | 'imported'>
|
|
|
|
|
|
|
@@ -429,16 +435,21 @@ function resolveInterfaceMembers(
|
|
|
;(base.calls || (base.calls = [])).push(...calls)
|
|
;(base.calls || (base.calls = [])).push(...calls)
|
|
|
}
|
|
}
|
|
|
} catch (e) {
|
|
} catch (e) {
|
|
|
- ctx.error(
|
|
|
|
|
- `Failed to resolve extends base type.\nIf this previously worked in 3.2, ` +
|
|
|
|
|
- `you can instruct the compiler to ignore this extend by adding ` +
|
|
|
|
|
- `/* @vue-ignore */ before it, for example:\n\n` +
|
|
|
|
|
- `interface Props extends /* @vue-ignore */ Base {}\n\n` +
|
|
|
|
|
- `Note: both in 3.2 or with the ignore, the properties in the base ` +
|
|
|
|
|
- `type are treated as fallthrough attrs at runtime.`,
|
|
|
|
|
- ext,
|
|
|
|
|
- scope,
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ // when called from inferRuntimeType context, silently ignore extends
|
|
|
|
|
+ // resolution failure so that properties defined in the interface can
|
|
|
|
|
+ // still be correctly resolved
|
|
|
|
|
+ if (!ctx.silentOnExtendsFailure) {
|
|
|
|
|
+ ctx.error(
|
|
|
|
|
+ `Failed to resolve extends base type.\nIf this previously worked in 3.2, ` +
|
|
|
|
|
+ `you can instruct the compiler to ignore this extend by adding ` +
|
|
|
|
|
+ `/* @vue-ignore */ before it, for example:\n\n` +
|
|
|
|
|
+ `interface Props extends /* @vue-ignore */ Base {}\n\n` +
|
|
|
|
|
+ `Note: both in 3.2 or with the ignore, the properties in the base ` +
|
|
|
|
|
+ `type are treated as fallthrough attrs at runtime.`,
|
|
|
|
|
+ ext,
|
|
|
|
|
+ scope,
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -1519,6 +1530,10 @@ export function inferRuntimeType(
|
|
|
return [UNKNOWN_TYPE]
|
|
return [UNKNOWN_TYPE]
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // set flag to silence extends resolution errors in this context
|
|
|
|
|
+ const prevSilent = ctx.silentOnExtendsFailure
|
|
|
|
|
+ ctx.silentOnExtendsFailure = true
|
|
|
|
|
+
|
|
|
try {
|
|
try {
|
|
|
switch (node.type) {
|
|
switch (node.type) {
|
|
|
case 'TSStringKeyword':
|
|
case 'TSStringKeyword':
|
|
@@ -1886,6 +1901,8 @@ export function inferRuntimeType(
|
|
|
}
|
|
}
|
|
|
} catch (e) {
|
|
} catch (e) {
|
|
|
// always soft fail on failed runtime type inference
|
|
// always soft fail on failed runtime type inference
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ ctx.silentOnExtendsFailure = prevSilent
|
|
|
}
|
|
}
|
|
|
return [UNKNOWN_TYPE] // no runtime check
|
|
return [UNKNOWN_TYPE] // no runtime check
|
|
|
}
|
|
}
|
|
@@ -1898,13 +1915,25 @@ function flattenTypes(
|
|
|
typeParameters: Record<string, Node> | undefined = undefined,
|
|
typeParameters: Record<string, Node> | undefined = undefined,
|
|
|
): string[] {
|
|
): string[] {
|
|
|
if (types.length === 1) {
|
|
if (types.length === 1) {
|
|
|
- return inferRuntimeType(ctx, types[0], scope, isKeyOf, typeParameters)
|
|
|
|
|
|
|
+ return inferRuntimeType(
|
|
|
|
|
+ ctx,
|
|
|
|
|
+ types[0],
|
|
|
|
|
+ (types[0] as MaybeWithScope)._ownerScope || scope,
|
|
|
|
|
+ isKeyOf,
|
|
|
|
|
+ typeParameters,
|
|
|
|
|
+ )
|
|
|
}
|
|
}
|
|
|
return [
|
|
return [
|
|
|
...new Set(
|
|
...new Set(
|
|
|
([] as string[]).concat(
|
|
([] as string[]).concat(
|
|
|
...types.map(t =>
|
|
...types.map(t =>
|
|
|
- inferRuntimeType(ctx, t, scope, isKeyOf, typeParameters),
|
|
|
|
|
|
|
+ inferRuntimeType(
|
|
|
|
|
+ ctx,
|
|
|
|
|
+ t,
|
|
|
|
|
+ (t as MaybeWithScope)._ownerScope || scope,
|
|
|
|
|
+ isKeyOf,
|
|
|
|
|
+ typeParameters,
|
|
|
|
|
+ ),
|
|
|
),
|
|
),
|
|
|
),
|
|
),
|
|
|
),
|
|
),
|