diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b1d39a4c09161..5da6244b552cb 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4840,15 +4840,60 @@ namespace ts { } } - function getDefaultOfTypeParameter(typeParameter: TypeParameter): Type { + /** + * Gets the default type for a type parameter. + * + * If the type parameter is the result of an instantiation, this gets the instantiated + * default type of its target. If the type parameter has no default type, `undefined` + * is returned. + * + * This function *does not* perform a circularity check. + */ + function getDefaultFromTypeParameter(typeParameter: TypeParameter): Type | undefined { + if (!typeParameter.default) { + if (typeParameter.target) { + const targetDefault = getDefaultFromTypeParameter(typeParameter.target); + typeParameter.default = targetDefault ? instantiateType(targetDefault, typeParameter.mapper) : noConstraintOrDefaultType; + } + else { + const defaultDeclaration = typeParameter.symbol && forEach(typeParameter.symbol.declarations, decl => isTypeParameter(decl) && decl.default); + typeParameter.default = defaultDeclaration ? getTypeFromTypeNode(defaultDeclaration) : noConstraintOrDefaultType; + } + } + return typeParameter.default === noConstraintOrDefaultType ? undefined : typeParameter.default; + } + + /** + * Gets the default type for a type parameter. + * + * If the type parameter is the result of an instantiation, this gets the instantiated + * default type of its target. If the type parameter has no default type, or if the default + * type circularly references the type parameter, `undefined` is returned. + * + * This function *does* perform a circularity check. + */ + function getDefaultOfTypeParameter(typeParameter: TypeParameter): Type | undefined { return hasNonCircularDefault(typeParameter) ? getDefaultFromTypeParameter(typeParameter) : undefined; } - function hasNonCircularDefault(type: TypeParameter) { - return getResolvedDefault(type) !== circularConstraintOrDefaultType; + /** + * Determines whether a type parameter has a non-circular default type. + * + * Note that this function also returns `true` if a type parameter *does not* have a + * default type. + */ + function hasNonCircularDefault(typeParameter: TypeParameter): boolean { + return getResolvedDefault(typeParameter) !== circularConstraintOrDefaultType; } - function getResolvedDefault(typeParameter: TypeParameter) { + /** + * Resolves the default type of a type parameter. + * + * If the type parameter has no default, the `noConstraintOrDefaultType` singleton is + * returned. If the type parameter has a circular default, the + * `circularConstraintOrDefaultType` singleton is returned. + */ + function getResolvedDefault(typeParameter: TypeParameter): Type { if (!typeParameter.resolvedDefault) { if (!pushTypeResolution(typeParameter, TypeSystemPropertyName.ResolvedDefault)) { return circularConstraintOrDefaultType; @@ -4863,6 +4908,12 @@ namespace ts { return typeParameter.resolvedDefault; } + /** + * Recursively resolves the default type for a type. + * + * If the type is a union or intersection type and any of its constituents is a circular + * reference, the `circularConstraintOrDefaultType` singleton is returned. + */ function getResolvedDefaultWorker(type: Type): Type { if (type.flags & TypeFlags.TypeParameter) { return getResolvedDefault(type); @@ -5173,6 +5224,14 @@ namespace ts { return minTypeArgumentCount; } + /** + * Fill in default types for unsupplied type arguments. If `typeArguments` is undefined + * when a default type is supplied, a new array will be created and returned. + * + * @param typeArguments The supplied type arguments. + * @param typeParameters The requested type parameters. + * @param minTypeArgumentCount The minimum number of required type arguments. + */ function fillMissingTypeArguments(typeArguments: Type[] | undefined, typeParameters: TypeParameter[] | undefined, minTypeArgumentCount: number) { const numTypeParameters = typeParameters ? typeParameters.length : 0; if (numTypeParameters) { @@ -5488,20 +5547,6 @@ namespace ts { return typeParameter.constraint === noConstraintOrDefaultType ? undefined : typeParameter.constraint; } - function getDefaultFromTypeParameter(typeParameter: TypeParameter): Type | undefined { - if (!typeParameter.default) { - if (typeParameter.target) { - const targetDefault = getDefaultFromTypeParameter(typeParameter.target); - typeParameter.default = targetDefault ? instantiateType(targetDefault, typeParameter.mapper) : noConstraintOrDefaultType; - } - else { - const defaultDeclaration = typeParameter.symbol && forEach(typeParameter.symbol.declarations, decl => isTypeParameter(decl) && decl.default); - typeParameter.default = defaultDeclaration ? getTypeFromTypeNode(defaultDeclaration) : noConstraintOrDefaultType; - } - } - return typeParameter.default === noConstraintOrDefaultType ? undefined : typeParameter.default; - } - function getParentSymbolOfTypeParameter(typeParameter: TypeParameter): Symbol { return getSymbolOfNode(getDeclarationOfKind(typeParameter.symbol, SyntaxKind.TypeParameter).parent); } @@ -13535,6 +13580,7 @@ namespace ts { ? createInferenceContext(originalCandidate, /*inferUnionTypes*/ false) : undefined; + // fix each supplied type argument in the inference context if (typeArguments) { for (let i = 0; i < typeArguments.length; i++) { inferenceContext.inferredTypes[i] = getTypeFromTypeNode(typeArguments[i]); @@ -13545,8 +13591,10 @@ namespace ts { while (true) { candidate = originalCandidate; if (candidate.typeParameters) { - typeArgumentsAreValid = typeArguments ? checkTypeArguments(candidate, typeArguments, inferenceContext.inferredTypes, /*reportErrors*/ false) : true; + // Check any supplied type arguments against the candidate. + typeArgumentsAreValid = !typeArguments || checkTypeArguments(candidate, typeArguments, inferenceContext.inferredTypes, /*reportErrors*/ false); if (typeArgumentsAreValid) { + // Infer any unsupplied type arguments for the candidate. inferTypeArguments(node, candidate, args, excludeArgument, inferenceContext); typeArgumentsAreValid = inferenceContext.failedTypeParameterIndex === undefined; } diff --git a/tests/baselines/reference/genericDefaults.js b/tests/baselines/reference/genericDefaults.js index aeedbd5d9e162..c61a42c965101 100644 --- a/tests/baselines/reference/genericDefaults.js +++ b/tests/baselines/reference/genericDefaults.js @@ -42,6 +42,28 @@ const f03c06 = f03(); const f03c07 = f03(1); const f03c08 = f03(1, 2); +declare function f04(a?: T, b?: U): [T, U]; +const f04c00 = f04(); +const f04c01 = f04(1); +const f04c02 = f04(1, 1); +const f04c03 = f04(); +const f04c04 = f04(1); +const f04c05 = f04(1, 2); +const f04c06 = f04(); +const f04c07 = f04(1); +const f04c08 = f04(1, 2); + +declare function f05(a?: T, b?: U): [T, U]; +const f05c00 = f05(); +const f05c01 = f05(1); +const f05c02 = f05(1, 1); +const f05c03 = f05(); +const f05c04 = f05(1); +const f05c05 = f05(1, 2); +const f05c06 = f05(); +const f05c07 = f05(1); +const f05c08 = f05(1, 2); + interface i00 { a: T; } const i00c00 = (x).a; const i00c01 = (>x).a; @@ -120,6 +142,24 @@ var f03c05 = f03(1, 2); var f03c06 = f03(); var f03c07 = f03(1); var f03c08 = f03(1, 2); +var f04c00 = f04(); +var f04c01 = f04(1); +var f04c02 = f04(1, 1); +var f04c03 = f04(); +var f04c04 = f04(1); +var f04c05 = f04(1, 2); +var f04c06 = f04(); +var f04c07 = f04(1); +var f04c08 = f04(1, 2); +var f05c00 = f05(); +var f05c01 = f05(1); +var f05c02 = f05(1, 1); +var f05c03 = f05(); +var f05c04 = f05(1); +var f05c05 = f05(1, 2); +var f05c06 = f05(); +var f05c07 = f05(1); +var f05c08 = f05(1, 2); var i00c00 = x.a; var i00c01 = x.a; var i01c00 = x.a; @@ -187,6 +227,46 @@ declare const f03c05: [number, number]; declare const f03c06: [number, number]; declare const f03c07: [number, number]; declare const f03c08: [number, number]; +declare function f04(a?: T, b?: U): [T, U]; +declare const f04c00: [{}, {} | { + a: number; +}]; +declare const f04c01: [number, number | { + a: number; +}]; +declare const f04c02: [number, number]; +declare const f04c03: [number, number | { + a: number; +}]; +declare const f04c04: [number, number | { + a: number; +}]; +declare const f04c05: [number, number]; +declare const f04c06: [number, number]; +declare const f04c07: [number, number]; +declare const f04c08: [number, number]; +declare function f05(a?: T, b?: U): [T, U]; +declare const f05c00: [{}, {} & { + a: number; +}]; +declare const f05c01: [number, number & { + a: number; +}]; +declare const f05c02: [number, number]; +declare const f05c03: [number, number & { + a: number; +}]; +declare const f05c04: [number, number & { + a: number; +}]; +declare const f05c05: [number, number]; +declare const f05c06: [number, number]; +declare const f05c07: [number, number]; +declare const f05c08: [number, number]; interface i00 { a: T; } diff --git a/tests/baselines/reference/genericDefaults.symbols b/tests/baselines/reference/genericDefaults.symbols index fe8dff0412ee6..a43b6fa9f4363 100644 --- a/tests/baselines/reference/genericDefaults.symbols +++ b/tests/baselines/reference/genericDefaults.symbols @@ -178,213 +178,311 @@ const f03c08 = f03(1, 2); >f03c08 : Symbol(f03c08, Decl(genericDefaults.ts, 41, 5)) >f03 : Symbol(f03, Decl(genericDefaults.ts, 30, 43)) +declare function f04(a?: T, b?: U): [T, U]; +>f04 : Symbol(f04, Decl(genericDefaults.ts, 41, 41)) +>T : Symbol(T, Decl(genericDefaults.ts, 43, 21)) +>U : Symbol(U, Decl(genericDefaults.ts, 43, 23)) +>T : Symbol(T, Decl(genericDefaults.ts, 43, 21)) +>a : Symbol(a, Decl(genericDefaults.ts, 43, 33)) +>a : Symbol(a, Decl(genericDefaults.ts, 43, 47)) +>T : Symbol(T, Decl(genericDefaults.ts, 43, 21)) +>b : Symbol(b, Decl(genericDefaults.ts, 43, 53)) +>U : Symbol(U, Decl(genericDefaults.ts, 43, 23)) +>T : Symbol(T, Decl(genericDefaults.ts, 43, 21)) +>U : Symbol(U, Decl(genericDefaults.ts, 43, 23)) + +const f04c00 = f04(); +>f04c00 : Symbol(f04c00, Decl(genericDefaults.ts, 44, 5)) +>f04 : Symbol(f04, Decl(genericDefaults.ts, 41, 41)) + +const f04c01 = f04(1); +>f04c01 : Symbol(f04c01, Decl(genericDefaults.ts, 45, 5)) +>f04 : Symbol(f04, Decl(genericDefaults.ts, 41, 41)) + +const f04c02 = f04(1, 1); +>f04c02 : Symbol(f04c02, Decl(genericDefaults.ts, 46, 5)) +>f04 : Symbol(f04, Decl(genericDefaults.ts, 41, 41)) + +const f04c03 = f04(); +>f04c03 : Symbol(f04c03, Decl(genericDefaults.ts, 47, 5)) +>f04 : Symbol(f04, Decl(genericDefaults.ts, 41, 41)) + +const f04c04 = f04(1); +>f04c04 : Symbol(f04c04, Decl(genericDefaults.ts, 48, 5)) +>f04 : Symbol(f04, Decl(genericDefaults.ts, 41, 41)) + +const f04c05 = f04(1, 2); +>f04c05 : Symbol(f04c05, Decl(genericDefaults.ts, 49, 5)) +>f04 : Symbol(f04, Decl(genericDefaults.ts, 41, 41)) + +const f04c06 = f04(); +>f04c06 : Symbol(f04c06, Decl(genericDefaults.ts, 50, 5)) +>f04 : Symbol(f04, Decl(genericDefaults.ts, 41, 41)) + +const f04c07 = f04(1); +>f04c07 : Symbol(f04c07, Decl(genericDefaults.ts, 51, 5)) +>f04 : Symbol(f04, Decl(genericDefaults.ts, 41, 41)) + +const f04c08 = f04(1, 2); +>f04c08 : Symbol(f04c08, Decl(genericDefaults.ts, 52, 5)) +>f04 : Symbol(f04, Decl(genericDefaults.ts, 41, 41)) + +declare function f05(a?: T, b?: U): [T, U]; +>f05 : Symbol(f05, Decl(genericDefaults.ts, 52, 41)) +>T : Symbol(T, Decl(genericDefaults.ts, 54, 21)) +>U : Symbol(U, Decl(genericDefaults.ts, 54, 23)) +>T : Symbol(T, Decl(genericDefaults.ts, 54, 21)) +>a : Symbol(a, Decl(genericDefaults.ts, 54, 33)) +>a : Symbol(a, Decl(genericDefaults.ts, 54, 47)) +>T : Symbol(T, Decl(genericDefaults.ts, 54, 21)) +>b : Symbol(b, Decl(genericDefaults.ts, 54, 53)) +>U : Symbol(U, Decl(genericDefaults.ts, 54, 23)) +>T : Symbol(T, Decl(genericDefaults.ts, 54, 21)) +>U : Symbol(U, Decl(genericDefaults.ts, 54, 23)) + +const f05c00 = f05(); +>f05c00 : Symbol(f05c00, Decl(genericDefaults.ts, 55, 5)) +>f05 : Symbol(f05, Decl(genericDefaults.ts, 52, 41)) + +const f05c01 = f05(1); +>f05c01 : Symbol(f05c01, Decl(genericDefaults.ts, 56, 5)) +>f05 : Symbol(f05, Decl(genericDefaults.ts, 52, 41)) + +const f05c02 = f05(1, 1); +>f05c02 : Symbol(f05c02, Decl(genericDefaults.ts, 57, 5)) +>f05 : Symbol(f05, Decl(genericDefaults.ts, 52, 41)) + +const f05c03 = f05(); +>f05c03 : Symbol(f05c03, Decl(genericDefaults.ts, 58, 5)) +>f05 : Symbol(f05, Decl(genericDefaults.ts, 52, 41)) + +const f05c04 = f05(1); +>f05c04 : Symbol(f05c04, Decl(genericDefaults.ts, 59, 5)) +>f05 : Symbol(f05, Decl(genericDefaults.ts, 52, 41)) + +const f05c05 = f05(1, 2); +>f05c05 : Symbol(f05c05, Decl(genericDefaults.ts, 60, 5)) +>f05 : Symbol(f05, Decl(genericDefaults.ts, 52, 41)) + +const f05c06 = f05(); +>f05c06 : Symbol(f05c06, Decl(genericDefaults.ts, 61, 5)) +>f05 : Symbol(f05, Decl(genericDefaults.ts, 52, 41)) + +const f05c07 = f05(1); +>f05c07 : Symbol(f05c07, Decl(genericDefaults.ts, 62, 5)) +>f05 : Symbol(f05, Decl(genericDefaults.ts, 52, 41)) + +const f05c08 = f05(1, 2); +>f05c08 : Symbol(f05c08, Decl(genericDefaults.ts, 63, 5)) +>f05 : Symbol(f05, Decl(genericDefaults.ts, 52, 41)) + interface i00 { a: T; } ->i00 : Symbol(i00, Decl(genericDefaults.ts, 41, 41)) ->T : Symbol(T, Decl(genericDefaults.ts, 43, 14)) ->a : Symbol(i00.a, Decl(genericDefaults.ts, 43, 27)) ->T : Symbol(T, Decl(genericDefaults.ts, 43, 14)) +>i00 : Symbol(i00, Decl(genericDefaults.ts, 63, 41)) +>T : Symbol(T, Decl(genericDefaults.ts, 65, 14)) +>a : Symbol(i00.a, Decl(genericDefaults.ts, 65, 27)) +>T : Symbol(T, Decl(genericDefaults.ts, 65, 14)) const i00c00 = (x).a; ->i00c00 : Symbol(i00c00, Decl(genericDefaults.ts, 44, 5)) ->(x).a : Symbol(i00.a, Decl(genericDefaults.ts, 43, 27)) ->i00 : Symbol(i00, Decl(genericDefaults.ts, 41, 41)) +>i00c00 : Symbol(i00c00, Decl(genericDefaults.ts, 66, 5)) +>(x).a : Symbol(i00.a, Decl(genericDefaults.ts, 65, 27)) +>i00 : Symbol(i00, Decl(genericDefaults.ts, 63, 41)) >x : Symbol(x, Decl(genericDefaults.ts, 0, 13)) ->a : Symbol(i00.a, Decl(genericDefaults.ts, 43, 27)) +>a : Symbol(i00.a, Decl(genericDefaults.ts, 65, 27)) const i00c01 = (>x).a; ->i00c01 : Symbol(i00c01, Decl(genericDefaults.ts, 45, 5)) ->(>x).a : Symbol(i00.a, Decl(genericDefaults.ts, 43, 27)) ->i00 : Symbol(i00, Decl(genericDefaults.ts, 41, 41)) +>i00c01 : Symbol(i00c01, Decl(genericDefaults.ts, 67, 5)) +>(>x).a : Symbol(i00.a, Decl(genericDefaults.ts, 65, 27)) +>i00 : Symbol(i00, Decl(genericDefaults.ts, 63, 41)) >x : Symbol(x, Decl(genericDefaults.ts, 0, 13)) ->a : Symbol(i00.a, Decl(genericDefaults.ts, 43, 27)) +>a : Symbol(i00.a, Decl(genericDefaults.ts, 65, 27)) interface i01 { a: [T, U]; } ->i01 : Symbol(i01, Decl(genericDefaults.ts, 45, 34)) ->T : Symbol(T, Decl(genericDefaults.ts, 47, 14)) ->U : Symbol(U, Decl(genericDefaults.ts, 47, 16)) ->T : Symbol(T, Decl(genericDefaults.ts, 47, 14)) ->a : Symbol(i01.a, Decl(genericDefaults.ts, 47, 25)) ->T : Symbol(T, Decl(genericDefaults.ts, 47, 14)) ->U : Symbol(U, Decl(genericDefaults.ts, 47, 16)) +>i01 : Symbol(i01, Decl(genericDefaults.ts, 67, 34)) +>T : Symbol(T, Decl(genericDefaults.ts, 69, 14)) +>U : Symbol(U, Decl(genericDefaults.ts, 69, 16)) +>T : Symbol(T, Decl(genericDefaults.ts, 69, 14)) +>a : Symbol(i01.a, Decl(genericDefaults.ts, 69, 25)) +>T : Symbol(T, Decl(genericDefaults.ts, 69, 14)) +>U : Symbol(U, Decl(genericDefaults.ts, 69, 16)) const i01c00 = (>x).a; ->i01c00 : Symbol(i01c00, Decl(genericDefaults.ts, 48, 5)) ->(>x).a : Symbol(i01.a, Decl(genericDefaults.ts, 47, 25)) ->i01 : Symbol(i01, Decl(genericDefaults.ts, 45, 34)) +>i01c00 : Symbol(i01c00, Decl(genericDefaults.ts, 70, 5)) +>(>x).a : Symbol(i01.a, Decl(genericDefaults.ts, 69, 25)) +>i01 : Symbol(i01, Decl(genericDefaults.ts, 67, 34)) >x : Symbol(x, Decl(genericDefaults.ts, 0, 13)) ->a : Symbol(i01.a, Decl(genericDefaults.ts, 47, 25)) +>a : Symbol(i01.a, Decl(genericDefaults.ts, 69, 25)) const i01c01 = (>x).a; ->i01c01 : Symbol(i01c01, Decl(genericDefaults.ts, 49, 5)) ->(>x).a : Symbol(i01.a, Decl(genericDefaults.ts, 47, 25)) ->i01 : Symbol(i01, Decl(genericDefaults.ts, 45, 34)) +>i01c01 : Symbol(i01c01, Decl(genericDefaults.ts, 71, 5)) +>(>x).a : Symbol(i01.a, Decl(genericDefaults.ts, 69, 25)) +>i01 : Symbol(i01, Decl(genericDefaults.ts, 67, 34)) >x : Symbol(x, Decl(genericDefaults.ts, 0, 13)) ->a : Symbol(i01.a, Decl(genericDefaults.ts, 47, 25)) +>a : Symbol(i01.a, Decl(genericDefaults.ts, 69, 25)) interface i02 { a: [T, U]; } ->i02 : Symbol(i02, Decl(genericDefaults.ts, 49, 42)) ->T : Symbol(T, Decl(genericDefaults.ts, 51, 14)) ->U : Symbol(U, Decl(genericDefaults.ts, 51, 31)) ->T : Symbol(T, Decl(genericDefaults.ts, 51, 14)) ->a : Symbol(i02.a, Decl(genericDefaults.ts, 51, 40)) ->T : Symbol(T, Decl(genericDefaults.ts, 51, 14)) ->U : Symbol(U, Decl(genericDefaults.ts, 51, 31)) +>i02 : Symbol(i02, Decl(genericDefaults.ts, 71, 42)) +>T : Symbol(T, Decl(genericDefaults.ts, 73, 14)) +>U : Symbol(U, Decl(genericDefaults.ts, 73, 31)) +>T : Symbol(T, Decl(genericDefaults.ts, 73, 14)) +>a : Symbol(i02.a, Decl(genericDefaults.ts, 73, 40)) +>T : Symbol(T, Decl(genericDefaults.ts, 73, 14)) +>U : Symbol(U, Decl(genericDefaults.ts, 73, 31)) const i02c00 = (>x).a; ->i02c00 : Symbol(i02c00, Decl(genericDefaults.ts, 52, 5)) ->(>x).a : Symbol(i02.a, Decl(genericDefaults.ts, 51, 40)) ->i02 : Symbol(i02, Decl(genericDefaults.ts, 49, 42)) +>i02c00 : Symbol(i02c00, Decl(genericDefaults.ts, 74, 5)) +>(>x).a : Symbol(i02.a, Decl(genericDefaults.ts, 73, 40)) +>i02 : Symbol(i02, Decl(genericDefaults.ts, 71, 42)) >x : Symbol(x, Decl(genericDefaults.ts, 0, 13)) ->a : Symbol(i02.a, Decl(genericDefaults.ts, 51, 40)) +>a : Symbol(i02.a, Decl(genericDefaults.ts, 73, 40)) const i02c01 = (>x).a; ->i02c01 : Symbol(i02c01, Decl(genericDefaults.ts, 53, 5)) ->(>x).a : Symbol(i02.a, Decl(genericDefaults.ts, 51, 40)) ->i02 : Symbol(i02, Decl(genericDefaults.ts, 49, 42)) +>i02c01 : Symbol(i02c01, Decl(genericDefaults.ts, 75, 5)) +>(>x).a : Symbol(i02.a, Decl(genericDefaults.ts, 73, 40)) +>i02 : Symbol(i02, Decl(genericDefaults.ts, 71, 42)) >x : Symbol(x, Decl(genericDefaults.ts, 0, 13)) ->a : Symbol(i02.a, Decl(genericDefaults.ts, 51, 40)) +>a : Symbol(i02.a, Decl(genericDefaults.ts, 73, 40)) const i02c02 = (>x).a; ->i02c02 : Symbol(i02c02, Decl(genericDefaults.ts, 54, 5)) ->(>x).a : Symbol(i02.a, Decl(genericDefaults.ts, 51, 40)) ->i02 : Symbol(i02, Decl(genericDefaults.ts, 49, 42)) +>i02c02 : Symbol(i02c02, Decl(genericDefaults.ts, 76, 5)) +>(>x).a : Symbol(i02.a, Decl(genericDefaults.ts, 73, 40)) +>i02 : Symbol(i02, Decl(genericDefaults.ts, 71, 42)) >x : Symbol(x, Decl(genericDefaults.ts, 0, 13)) ->a : Symbol(i02.a, Decl(genericDefaults.ts, 51, 40)) +>a : Symbol(i02.a, Decl(genericDefaults.ts, 73, 40)) const i02c03 = (>x).a; ->i02c03 : Symbol(i02c03, Decl(genericDefaults.ts, 55, 5)) ->(>x).a : Symbol(i02.a, Decl(genericDefaults.ts, 51, 40)) ->i02 : Symbol(i02, Decl(genericDefaults.ts, 49, 42)) +>i02c03 : Symbol(i02c03, Decl(genericDefaults.ts, 77, 5)) +>(>x).a : Symbol(i02.a, Decl(genericDefaults.ts, 73, 40)) +>i02 : Symbol(i02, Decl(genericDefaults.ts, 71, 42)) >x : Symbol(x, Decl(genericDefaults.ts, 0, 13)) ->a : Symbol(i02.a, Decl(genericDefaults.ts, 51, 40)) +>a : Symbol(i02.a, Decl(genericDefaults.ts, 73, 40)) const i02c04 = (>x).a; ->i02c04 : Symbol(i02c04, Decl(genericDefaults.ts, 56, 5)) ->(>x).a : Symbol(i02.a, Decl(genericDefaults.ts, 51, 40)) ->i02 : Symbol(i02, Decl(genericDefaults.ts, 49, 42)) +>i02c04 : Symbol(i02c04, Decl(genericDefaults.ts, 78, 5)) +>(>x).a : Symbol(i02.a, Decl(genericDefaults.ts, 73, 40)) +>i02 : Symbol(i02, Decl(genericDefaults.ts, 71, 42)) >x : Symbol(x, Decl(genericDefaults.ts, 0, 13)) ->a : Symbol(i02.a, Decl(genericDefaults.ts, 51, 40)) +>a : Symbol(i02.a, Decl(genericDefaults.ts, 73, 40)) interface i03 { a: [T, U]; } ->i03 : Symbol(i03, Decl(genericDefaults.ts, 56, 37)) ->T : Symbol(T, Decl(genericDefaults.ts, 58, 14)) ->U : Symbol(U, Decl(genericDefaults.ts, 58, 31)) ->T : Symbol(T, Decl(genericDefaults.ts, 58, 14)) ->T : Symbol(T, Decl(genericDefaults.ts, 58, 14)) ->a : Symbol(i03.a, Decl(genericDefaults.ts, 58, 50)) ->T : Symbol(T, Decl(genericDefaults.ts, 58, 14)) ->U : Symbol(U, Decl(genericDefaults.ts, 58, 31)) +>i03 : Symbol(i03, Decl(genericDefaults.ts, 78, 37)) +>T : Symbol(T, Decl(genericDefaults.ts, 80, 14)) +>U : Symbol(U, Decl(genericDefaults.ts, 80, 31)) +>T : Symbol(T, Decl(genericDefaults.ts, 80, 14)) +>T : Symbol(T, Decl(genericDefaults.ts, 80, 14)) +>a : Symbol(i03.a, Decl(genericDefaults.ts, 80, 50)) +>T : Symbol(T, Decl(genericDefaults.ts, 80, 14)) +>U : Symbol(U, Decl(genericDefaults.ts, 80, 31)) const i03c00 = (>x).a; ->i03c00 : Symbol(i03c00, Decl(genericDefaults.ts, 59, 5)) ->(>x).a : Symbol(i03.a, Decl(genericDefaults.ts, 58, 50)) ->i03 : Symbol(i03, Decl(genericDefaults.ts, 56, 37)) +>i03c00 : Symbol(i03c00, Decl(genericDefaults.ts, 81, 5)) +>(>x).a : Symbol(i03.a, Decl(genericDefaults.ts, 80, 50)) +>i03 : Symbol(i03, Decl(genericDefaults.ts, 78, 37)) >x : Symbol(x, Decl(genericDefaults.ts, 0, 13)) ->a : Symbol(i03.a, Decl(genericDefaults.ts, 58, 50)) +>a : Symbol(i03.a, Decl(genericDefaults.ts, 80, 50)) const i03c01 = (>x).a; ->i03c01 : Symbol(i03c01, Decl(genericDefaults.ts, 60, 5)) ->(>x).a : Symbol(i03.a, Decl(genericDefaults.ts, 58, 50)) ->i03 : Symbol(i03, Decl(genericDefaults.ts, 56, 37)) +>i03c01 : Symbol(i03c01, Decl(genericDefaults.ts, 82, 5)) +>(>x).a : Symbol(i03.a, Decl(genericDefaults.ts, 80, 50)) +>i03 : Symbol(i03, Decl(genericDefaults.ts, 78, 37)) >x : Symbol(x, Decl(genericDefaults.ts, 0, 13)) ->a : Symbol(i03.a, Decl(genericDefaults.ts, 58, 50)) +>a : Symbol(i03.a, Decl(genericDefaults.ts, 80, 50)) const i03c02 = (>x).a; ->i03c02 : Symbol(i03c02, Decl(genericDefaults.ts, 61, 5)) ->(>x).a : Symbol(i03.a, Decl(genericDefaults.ts, 58, 50)) ->i03 : Symbol(i03, Decl(genericDefaults.ts, 56, 37)) +>i03c02 : Symbol(i03c02, Decl(genericDefaults.ts, 83, 5)) +>(>x).a : Symbol(i03.a, Decl(genericDefaults.ts, 80, 50)) +>i03 : Symbol(i03, Decl(genericDefaults.ts, 78, 37)) >x : Symbol(x, Decl(genericDefaults.ts, 0, 13)) ->a : Symbol(i03.a, Decl(genericDefaults.ts, 58, 50)) +>a : Symbol(i03.a, Decl(genericDefaults.ts, 80, 50)) const i03c03 = (>x).a; ->i03c03 : Symbol(i03c03, Decl(genericDefaults.ts, 62, 5)) ->(>x).a : Symbol(i03.a, Decl(genericDefaults.ts, 58, 50)) ->i03 : Symbol(i03, Decl(genericDefaults.ts, 56, 37)) +>i03c03 : Symbol(i03c03, Decl(genericDefaults.ts, 84, 5)) +>(>x).a : Symbol(i03.a, Decl(genericDefaults.ts, 80, 50)) +>i03 : Symbol(i03, Decl(genericDefaults.ts, 78, 37)) >x : Symbol(x, Decl(genericDefaults.ts, 0, 13)) ->a : Symbol(i03.a, Decl(genericDefaults.ts, 58, 50)) +>a : Symbol(i03.a, Decl(genericDefaults.ts, 80, 50)) const i03c04 = (>x).a; ->i03c04 : Symbol(i03c04, Decl(genericDefaults.ts, 63, 5)) ->(>x).a : Symbol(i03.a, Decl(genericDefaults.ts, 58, 50)) ->i03 : Symbol(i03, Decl(genericDefaults.ts, 56, 37)) +>i03c04 : Symbol(i03c04, Decl(genericDefaults.ts, 85, 5)) +>(>x).a : Symbol(i03.a, Decl(genericDefaults.ts, 80, 50)) +>i03 : Symbol(i03, Decl(genericDefaults.ts, 78, 37)) >x : Symbol(x, Decl(genericDefaults.ts, 0, 13)) ->a : Symbol(i03.a, Decl(genericDefaults.ts, 58, 50)) +>a : Symbol(i03.a, Decl(genericDefaults.ts, 80, 50)) interface Base01 { a: T; } ->Base01 : Symbol(Base01, Decl(genericDefaults.ts, 63, 37), Decl(genericDefaults.ts, 68, 13)) ->T : Symbol(T, Decl(genericDefaults.ts, 65, 17)) ->a : Symbol(Base01.a, Decl(genericDefaults.ts, 65, 21)) ->T : Symbol(T, Decl(genericDefaults.ts, 65, 17)) +>Base01 : Symbol(Base01, Decl(genericDefaults.ts, 85, 37), Decl(genericDefaults.ts, 90, 13)) +>T : Symbol(T, Decl(genericDefaults.ts, 87, 17)) +>a : Symbol(Base01.a, Decl(genericDefaults.ts, 87, 21)) +>T : Symbol(T, Decl(genericDefaults.ts, 87, 17)) interface Base01Constructor { new (a?: T): Base01; } ->Base01Constructor : Symbol(Base01Constructor, Decl(genericDefaults.ts, 65, 29)) ->T : Symbol(T, Decl(genericDefaults.ts, 66, 35)) ->a : Symbol(a, Decl(genericDefaults.ts, 66, 47)) ->T : Symbol(T, Decl(genericDefaults.ts, 66, 35)) ->Base01 : Symbol(Base01, Decl(genericDefaults.ts, 63, 37), Decl(genericDefaults.ts, 68, 13)) ->T : Symbol(T, Decl(genericDefaults.ts, 66, 35)) +>Base01Constructor : Symbol(Base01Constructor, Decl(genericDefaults.ts, 87, 29)) +>T : Symbol(T, Decl(genericDefaults.ts, 88, 35)) +>a : Symbol(a, Decl(genericDefaults.ts, 88, 47)) +>T : Symbol(T, Decl(genericDefaults.ts, 88, 35)) +>Base01 : Symbol(Base01, Decl(genericDefaults.ts, 85, 37), Decl(genericDefaults.ts, 90, 13)) +>T : Symbol(T, Decl(genericDefaults.ts, 88, 35)) declare const Base01: Base01Constructor; ->Base01 : Symbol(Base01, Decl(genericDefaults.ts, 63, 37), Decl(genericDefaults.ts, 68, 13)) ->Base01Constructor : Symbol(Base01Constructor, Decl(genericDefaults.ts, 65, 29)) +>Base01 : Symbol(Base01, Decl(genericDefaults.ts, 85, 37), Decl(genericDefaults.ts, 90, 13)) +>Base01Constructor : Symbol(Base01Constructor, Decl(genericDefaults.ts, 87, 29)) const Base01c00 = new Base01(); ->Base01c00 : Symbol(Base01c00, Decl(genericDefaults.ts, 69, 5)) ->Base01 : Symbol(Base01, Decl(genericDefaults.ts, 63, 37), Decl(genericDefaults.ts, 68, 13)) +>Base01c00 : Symbol(Base01c00, Decl(genericDefaults.ts, 91, 5)) +>Base01 : Symbol(Base01, Decl(genericDefaults.ts, 85, 37), Decl(genericDefaults.ts, 90, 13)) const Base01c01 = new Base01(1); ->Base01c01 : Symbol(Base01c01, Decl(genericDefaults.ts, 70, 5)) ->Base01 : Symbol(Base01, Decl(genericDefaults.ts, 63, 37), Decl(genericDefaults.ts, 68, 13)) +>Base01c01 : Symbol(Base01c01, Decl(genericDefaults.ts, 92, 5)) +>Base01 : Symbol(Base01, Decl(genericDefaults.ts, 85, 37), Decl(genericDefaults.ts, 90, 13)) const Base01c02 = new Base01(); ->Base01c02 : Symbol(Base01c02, Decl(genericDefaults.ts, 71, 5)) ->Base01 : Symbol(Base01, Decl(genericDefaults.ts, 63, 37), Decl(genericDefaults.ts, 68, 13)) +>Base01c02 : Symbol(Base01c02, Decl(genericDefaults.ts, 93, 5)) +>Base01 : Symbol(Base01, Decl(genericDefaults.ts, 85, 37), Decl(genericDefaults.ts, 90, 13)) const Base01c03 = new Base01(1); ->Base01c03 : Symbol(Base01c03, Decl(genericDefaults.ts, 72, 5)) ->Base01 : Symbol(Base01, Decl(genericDefaults.ts, 63, 37), Decl(genericDefaults.ts, 68, 13)) +>Base01c03 : Symbol(Base01c03, Decl(genericDefaults.ts, 94, 5)) +>Base01 : Symbol(Base01, Decl(genericDefaults.ts, 85, 37), Decl(genericDefaults.ts, 90, 13)) declare class Derived01 extends Base01 { } ->Derived01 : Symbol(Derived01, Decl(genericDefaults.ts, 72, 40)) ->T : Symbol(T, Decl(genericDefaults.ts, 74, 24)) ->Base01 : Symbol(Base01, Decl(genericDefaults.ts, 63, 37), Decl(genericDefaults.ts, 68, 13)) ->T : Symbol(T, Decl(genericDefaults.ts, 74, 24)) +>Derived01 : Symbol(Derived01, Decl(genericDefaults.ts, 94, 40)) +>T : Symbol(T, Decl(genericDefaults.ts, 96, 24)) +>Base01 : Symbol(Base01, Decl(genericDefaults.ts, 85, 37), Decl(genericDefaults.ts, 90, 13)) +>T : Symbol(T, Decl(genericDefaults.ts, 96, 24)) const Derived01c00 = new Derived01(); ->Derived01c00 : Symbol(Derived01c00, Decl(genericDefaults.ts, 75, 5)) ->Derived01 : Symbol(Derived01, Decl(genericDefaults.ts, 72, 40)) +>Derived01c00 : Symbol(Derived01c00, Decl(genericDefaults.ts, 97, 5)) +>Derived01 : Symbol(Derived01, Decl(genericDefaults.ts, 94, 40)) const Derived01c01 = new Derived01(1); ->Derived01c01 : Symbol(Derived01c01, Decl(genericDefaults.ts, 76, 5)) ->Derived01 : Symbol(Derived01, Decl(genericDefaults.ts, 72, 40)) +>Derived01c01 : Symbol(Derived01c01, Decl(genericDefaults.ts, 98, 5)) +>Derived01 : Symbol(Derived01, Decl(genericDefaults.ts, 94, 40)) const Derived01c02 = new Derived01(); ->Derived01c02 : Symbol(Derived01c02, Decl(genericDefaults.ts, 77, 5)) ->Derived01 : Symbol(Derived01, Decl(genericDefaults.ts, 72, 40)) +>Derived01c02 : Symbol(Derived01c02, Decl(genericDefaults.ts, 99, 5)) +>Derived01 : Symbol(Derived01, Decl(genericDefaults.ts, 94, 40)) const Derived01c03 = new Derived01(1); ->Derived01c03 : Symbol(Derived01c03, Decl(genericDefaults.ts, 78, 5)) ->Derived01 : Symbol(Derived01, Decl(genericDefaults.ts, 72, 40)) +>Derived01c03 : Symbol(Derived01c03, Decl(genericDefaults.ts, 100, 5)) +>Derived01 : Symbol(Derived01, Decl(genericDefaults.ts, 94, 40)) declare class Derived02 extends Base01 { } ->Derived02 : Symbol(Derived02, Decl(genericDefaults.ts, 78, 46)) ->T : Symbol(T, Decl(genericDefaults.ts, 80, 24)) ->Base01 : Symbol(Base01, Decl(genericDefaults.ts, 63, 37), Decl(genericDefaults.ts, 68, 13)) ->T : Symbol(T, Decl(genericDefaults.ts, 80, 24)) +>Derived02 : Symbol(Derived02, Decl(genericDefaults.ts, 100, 46)) +>T : Symbol(T, Decl(genericDefaults.ts, 102, 24)) +>Base01 : Symbol(Base01, Decl(genericDefaults.ts, 85, 37), Decl(genericDefaults.ts, 90, 13)) +>T : Symbol(T, Decl(genericDefaults.ts, 102, 24)) const Derived02c00 = new Derived02(); ->Derived02c00 : Symbol(Derived02c00, Decl(genericDefaults.ts, 81, 5)) ->Derived02 : Symbol(Derived02, Decl(genericDefaults.ts, 78, 46)) +>Derived02c00 : Symbol(Derived02c00, Decl(genericDefaults.ts, 103, 5)) +>Derived02 : Symbol(Derived02, Decl(genericDefaults.ts, 100, 46)) const Derived02c01 = new Derived02(1); ->Derived02c01 : Symbol(Derived02c01, Decl(genericDefaults.ts, 82, 5)) ->Derived02 : Symbol(Derived02, Decl(genericDefaults.ts, 78, 46)) +>Derived02c01 : Symbol(Derived02c01, Decl(genericDefaults.ts, 104, 5)) +>Derived02 : Symbol(Derived02, Decl(genericDefaults.ts, 100, 46)) const Derived02c02 = new Derived02(); ->Derived02c02 : Symbol(Derived02c02, Decl(genericDefaults.ts, 83, 5)) ->Derived02 : Symbol(Derived02, Decl(genericDefaults.ts, 78, 46)) +>Derived02c02 : Symbol(Derived02c02, Decl(genericDefaults.ts, 105, 5)) +>Derived02 : Symbol(Derived02, Decl(genericDefaults.ts, 100, 46)) const Derived02c03 = new Derived02(1); ->Derived02c03 : Symbol(Derived02c03, Decl(genericDefaults.ts, 84, 5)) ->Derived02 : Symbol(Derived02, Decl(genericDefaults.ts, 78, 46)) +>Derived02c03 : Symbol(Derived02c03, Decl(genericDefaults.ts, 106, 5)) +>Derived02 : Symbol(Derived02, Decl(genericDefaults.ts, 100, 46)) diff --git a/tests/baselines/reference/genericDefaults.types b/tests/baselines/reference/genericDefaults.types index c693d4e4048d0..7f50e03744c04 100644 --- a/tests/baselines/reference/genericDefaults.types +++ b/tests/baselines/reference/genericDefaults.types @@ -242,6 +242,140 @@ const f03c08 = f03(1, 2); >1 : 1 >2 : 2 +declare function f04(a?: T, b?: U): [T, U]; +>f04 : (a?: T, b?: U) => [T, U] +>T : T +>U : U +>T : T +>a : number +>a : T +>T : T +>b : U +>U : U +>T : T +>U : U + +const f04c00 = f04(); +>f04c00 : [{}, {} | { a: number; }] +>f04() : [{}, {} | { a: number; }] +>f04 : (a?: T, b?: U) => [T, U] + +const f04c01 = f04(1); +>f04c01 : [number, number | { a: number; }] +>f04(1) : [number, number | { a: number; }] +>f04 : (a?: T, b?: U) => [T, U] +>1 : 1 + +const f04c02 = f04(1, 1); +>f04c02 : [number, number] +>f04(1, 1) : [number, number] +>f04 : (a?: T, b?: U) => [T, U] +>1 : 1 +>1 : 1 + +const f04c03 = f04(); +>f04c03 : [number, number | { a: number; }] +>f04() : [number, number | { a: number; }] +>f04 : (a?: T, b?: U) => [T, U] + +const f04c04 = f04(1); +>f04c04 : [number, number | { a: number; }] +>f04(1) : [number, number | { a: number; }] +>f04 : (a?: T, b?: U) => [T, U] +>1 : 1 + +const f04c05 = f04(1, 2); +>f04c05 : [number, number] +>f04(1, 2) : [number, number] +>f04 : (a?: T, b?: U) => [T, U] +>1 : 1 +>2 : 2 + +const f04c06 = f04(); +>f04c06 : [number, number] +>f04() : [number, number] +>f04 : (a?: T, b?: U) => [T, U] + +const f04c07 = f04(1); +>f04c07 : [number, number] +>f04(1) : [number, number] +>f04 : (a?: T, b?: U) => [T, U] +>1 : 1 + +const f04c08 = f04(1, 2); +>f04c08 : [number, number] +>f04(1, 2) : [number, number] +>f04 : (a?: T, b?: U) => [T, U] +>1 : 1 +>2 : 2 + +declare function f05(a?: T, b?: U): [T, U]; +>f05 : (a?: T, b?: U) => [T, U] +>T : T +>U : U +>T : T +>a : number +>a : T +>T : T +>b : U +>U : U +>T : T +>U : U + +const f05c00 = f05(); +>f05c00 : [{}, {} & { a: number; }] +>f05() : [{}, {} & { a: number; }] +>f05 : (a?: T, b?: U) => [T, U] + +const f05c01 = f05(1); +>f05c01 : [number, number & { a: number; }] +>f05(1) : [number, number & { a: number; }] +>f05 : (a?: T, b?: U) => [T, U] +>1 : 1 + +const f05c02 = f05(1, 1); +>f05c02 : [number, number] +>f05(1, 1) : [number, number] +>f05 : (a?: T, b?: U) => [T, U] +>1 : 1 +>1 : 1 + +const f05c03 = f05(); +>f05c03 : [number, number & { a: number; }] +>f05() : [number, number & { a: number; }] +>f05 : (a?: T, b?: U) => [T, U] + +const f05c04 = f05(1); +>f05c04 : [number, number & { a: number; }] +>f05(1) : [number, number & { a: number; }] +>f05 : (a?: T, b?: U) => [T, U] +>1 : 1 + +const f05c05 = f05(1, 2); +>f05c05 : [number, number] +>f05(1, 2) : [number, number] +>f05 : (a?: T, b?: U) => [T, U] +>1 : 1 +>2 : 2 + +const f05c06 = f05(); +>f05c06 : [number, number] +>f05() : [number, number] +>f05 : (a?: T, b?: U) => [T, U] + +const f05c07 = f05(1); +>f05c07 : [number, number] +>f05(1) : [number, number] +>f05 : (a?: T, b?: U) => [T, U] +>1 : 1 + +const f05c08 = f05(1, 2); +>f05c08 : [number, number] +>f05(1, 2) : [number, number] +>f05 : (a?: T, b?: U) => [T, U] +>1 : 1 +>2 : 2 + interface i00 { a: T; } >i00 : i00 >T : T diff --git a/tests/baselines/reference/genericDefaultsErrors.errors.txt b/tests/baselines/reference/genericDefaultsErrors.errors.txt index 5e19e25f270e9..aaf1f0b6cf014 100644 --- a/tests/baselines/reference/genericDefaultsErrors.errors.txt +++ b/tests/baselines/reference/genericDefaultsErrors.errors.txt @@ -7,25 +7,33 @@ tests/cases/compiler/genericDefaultsErrors.ts(8,59): error TS2344: Type 'T' does Type 'string' is not assignable to type 'number'. tests/cases/compiler/genericDefaultsErrors.ts(9,44): error TS2344: Type 'T' does not satisfy the constraint 'number'. tests/cases/compiler/genericDefaultsErrors.ts(10,39): error TS2344: Type 'number' does not satisfy the constraint 'T'. -tests/cases/compiler/genericDefaultsErrors.ts(14,1): error TS2346: Supplied parameters do not match any signature of call target. -tests/cases/compiler/genericDefaultsErrors.ts(17,1): error TS2346: Supplied parameters do not match any signature of call target. -tests/cases/compiler/genericDefaultsErrors.ts(20,11): error TS2428: All declarations of 'i00' must have identical type parameters. -tests/cases/compiler/genericDefaultsErrors.ts(23,11): error TS2428: All declarations of 'i01' must have identical type parameters. -tests/cases/compiler/genericDefaultsErrors.ts(25,19): error TS2706: Type parameter 'T' has a circular default. -tests/cases/compiler/genericDefaultsErrors.ts(26,19): error TS2706: Type parameter 'T' has a circular default. -tests/cases/compiler/genericDefaultsErrors.ts(26,26): error TS2706: Type parameter 'U' has a circular default. -tests/cases/compiler/genericDefaultsErrors.ts(27,22): error TS2705: Required type parameters may not follow optional type parameters -tests/cases/compiler/genericDefaultsErrors.ts(28,34): error TS2344: Type 'number' does not satisfy the constraint 'string'. -tests/cases/compiler/genericDefaultsErrors.ts(29,52): error TS2344: Type 'T' does not satisfy the constraint 'number'. +tests/cases/compiler/genericDefaultsErrors.ts(11,26): error TS2706: Type parameter 'T' has a circular default. +tests/cases/compiler/genericDefaultsErrors.ts(11,33): error TS2706: Type parameter 'U' has a circular default. +tests/cases/compiler/genericDefaultsErrors.ts(12,26): error TS2706: Type parameter 'T' has a circular default. +tests/cases/compiler/genericDefaultsErrors.ts(12,33): error TS2706: Type parameter 'U' has a circular default. +tests/cases/compiler/genericDefaultsErrors.ts(13,26): error TS2706: Type parameter 'T' has a circular default. +tests/cases/compiler/genericDefaultsErrors.ts(13,33): error TS2706: Type parameter 'U' has a circular default. +tests/cases/compiler/genericDefaultsErrors.ts(14,26): error TS2706: Type parameter 'T' has a circular default. +tests/cases/compiler/genericDefaultsErrors.ts(14,33): error TS2706: Type parameter 'U' has a circular default. +tests/cases/compiler/genericDefaultsErrors.ts(18,1): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/compiler/genericDefaultsErrors.ts(21,1): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/compiler/genericDefaultsErrors.ts(24,11): error TS2428: All declarations of 'i00' must have identical type parameters. +tests/cases/compiler/genericDefaultsErrors.ts(27,11): error TS2428: All declarations of 'i01' must have identical type parameters. +tests/cases/compiler/genericDefaultsErrors.ts(29,19): error TS2706: Type parameter 'T' has a circular default. +tests/cases/compiler/genericDefaultsErrors.ts(30,19): error TS2706: Type parameter 'T' has a circular default. +tests/cases/compiler/genericDefaultsErrors.ts(30,26): error TS2706: Type parameter 'U' has a circular default. +tests/cases/compiler/genericDefaultsErrors.ts(31,22): error TS2705: Required type parameters may not follow optional type parameters +tests/cases/compiler/genericDefaultsErrors.ts(32,34): error TS2344: Type 'number' does not satisfy the constraint 'string'. +tests/cases/compiler/genericDefaultsErrors.ts(33,52): error TS2344: Type 'T' does not satisfy the constraint 'number'. Type 'string' is not assignable to type 'number'. -tests/cases/compiler/genericDefaultsErrors.ts(30,37): error TS2344: Type 'T' does not satisfy the constraint 'number'. -tests/cases/compiler/genericDefaultsErrors.ts(31,32): error TS2344: Type 'number' does not satisfy the constraint 'T'. -tests/cases/compiler/genericDefaultsErrors.ts(34,15): error TS2707: Generic type 'i09' requires between 2 and 3 type arguments -tests/cases/compiler/genericDefaultsErrors.ts(35,15): error TS2707: Generic type 'i09' requires between 2 and 3 type arguments +tests/cases/compiler/genericDefaultsErrors.ts(34,37): error TS2344: Type 'T' does not satisfy the constraint 'number'. +tests/cases/compiler/genericDefaultsErrors.ts(35,32): error TS2344: Type 'number' does not satisfy the constraint 'T'. tests/cases/compiler/genericDefaultsErrors.ts(38,15): error TS2707: Generic type 'i09' requires between 2 and 3 type arguments +tests/cases/compiler/genericDefaultsErrors.ts(39,15): error TS2707: Generic type 'i09' requires between 2 and 3 type arguments +tests/cases/compiler/genericDefaultsErrors.ts(42,15): error TS2707: Generic type 'i09' requires between 2 and 3 type arguments -==== tests/cases/compiler/genericDefaultsErrors.ts (23 errors) ==== +==== tests/cases/compiler/genericDefaultsErrors.ts (31 errors) ==== declare const x: any; @@ -53,15 +61,35 @@ tests/cases/compiler/genericDefaultsErrors.ts(38,15): error TS2707: Generic type declare function f06(): void; ~~~~~~ !!! error TS2344: Type 'number' does not satisfy the constraint 'T'. + declare function f07(): void; + ~ +!!! error TS2706: Type parameter 'T' has a circular default. + ~~~~~~~~~~~~~~~~~ +!!! error TS2706: Type parameter 'U' has a circular default. + declare function f08(): void; + ~ +!!! error TS2706: Type parameter 'T' has a circular default. + ~~~~~~~~~~~~~~~~~ +!!! error TS2706: Type parameter 'U' has a circular default. + declare function f09(): void; + ~ +!!! error TS2706: Type parameter 'T' has a circular default. + ~~~~~~~~~~~~~~~~~ +!!! error TS2706: Type parameter 'U' has a circular default. + declare function f10(): void; + ~ +!!! error TS2706: Type parameter 'T' has a circular default. + ~~~~~~~~~~~~~~~~~ +!!! error TS2706: Type parameter 'U' has a circular default. - declare function f07(): void; - f07(); // ok - f07<1>(); // error + declare function f11(): void; + f11(); // ok + f11<1>(); // error ~~~~~~~~ !!! error TS2346: Supplied parameters do not match any signature of call target. - f07<1, 2>(); // ok - f07<1, 2, 3>(); // ok - f07<1, 2, 3, 4>(); // error + f11<1, 2>(); // ok + f11<1, 2, 3>(); // ok + f11<1, 2, 3, 4>(); // error ~~~~~~~~~~~~~~~~~ !!! error TS2346: Supplied parameters do not match any signature of call target. diff --git a/tests/baselines/reference/genericDefaultsErrors.js b/tests/baselines/reference/genericDefaultsErrors.js index 9615ad2e36299..6a624fae4d483 100644 --- a/tests/baselines/reference/genericDefaultsErrors.js +++ b/tests/baselines/reference/genericDefaultsErrors.js @@ -9,13 +9,17 @@ declare function f03(): void; declare function f04(): void; declare function f05(): void; declare function f06(): void; +declare function f07(): void; +declare function f08(): void; +declare function f09(): void; +declare function f10(): void; -declare function f07(): void; -f07(); // ok -f07<1>(); // error -f07<1, 2>(); // ok -f07<1, 2, 3>(); // ok -f07<1, 2, 3, 4>(); // error +declare function f11(): void; +f11(); // ok +f11<1>(); // error +f11<1, 2>(); // ok +f11<1, 2, 3>(); // ok +f11<1, 2, 3, 4>(); // error interface i00 { } interface i00 { } @@ -39,11 +43,11 @@ type i09t03 = i09<1, 2, 3>; // ok type i09t04 = i09<1, 2, 3, 4>; // error //// [genericDefaultsErrors.js] -f07(); // ok -f07(); // error -f07(); // ok -f07(); // ok -f07(); // error +f11(); // ok +f11(); // error +f11(); // ok +f11(); // ok +f11(); // error //// [genericDefaultsErrors.d.ts] @@ -55,7 +59,19 @@ declare function f03(): void; declare function f04(): void; declare function f05(): void; declare function f06(): void; -declare function f07(): void; +declare function f07(): void; +declare function f08(): void; +declare function f09(): void; +declare function f10(): void; +declare function f11(): void; interface i00 { } interface i00 { diff --git a/tests/cases/compiler/genericDefaults.ts b/tests/cases/compiler/genericDefaults.ts index 9ab0ede05b6e8..abba8f2d8d673 100644 --- a/tests/cases/compiler/genericDefaults.ts +++ b/tests/cases/compiler/genericDefaults.ts @@ -42,6 +42,28 @@ const f03c06 = f03(); const f03c07 = f03(1); const f03c08 = f03(1, 2); +declare function f04(a?: T, b?: U): [T, U]; +const f04c00 = f04(); +const f04c01 = f04(1); +const f04c02 = f04(1, 1); +const f04c03 = f04(); +const f04c04 = f04(1); +const f04c05 = f04(1, 2); +const f04c06 = f04(); +const f04c07 = f04(1); +const f04c08 = f04(1, 2); + +declare function f05(a?: T, b?: U): [T, U]; +const f05c00 = f05(); +const f05c01 = f05(1); +const f05c02 = f05(1, 1); +const f05c03 = f05(); +const f05c04 = f05(1); +const f05c05 = f05(1, 2); +const f05c06 = f05(); +const f05c07 = f05(1); +const f05c08 = f05(1, 2); + interface i00 { a: T; } const i00c00 = (x).a; const i00c01 = (>x).a; diff --git a/tests/cases/compiler/genericDefaultsErrors.ts b/tests/cases/compiler/genericDefaultsErrors.ts index 470b4998e926e..e7fb7be81aeed 100644 --- a/tests/cases/compiler/genericDefaultsErrors.ts +++ b/tests/cases/compiler/genericDefaultsErrors.ts @@ -9,13 +9,17 @@ declare function f03(): void; declare function f04(): void; declare function f05(): void; declare function f06(): void; +declare function f07(): void; +declare function f08(): void; +declare function f09(): void; +declare function f10(): void; -declare function f07(): void; -f07(); // ok -f07<1>(); // error -f07<1, 2>(); // ok -f07<1, 2, 3>(); // ok -f07<1, 2, 3, 4>(); // error +declare function f11(): void; +f11(); // ok +f11<1>(); // error +f11<1, 2>(); // ok +f11<1, 2, 3>(); // ok +f11<1, 2, 3, 4>(); // error interface i00 { } interface i00 { }