From 7bc10c7549c8656171de0e2d86c18226b9e368d1 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Fri, 14 Apr 2017 16:29:57 -0700 Subject: [PATCH 01/11] Widen inference candidates for error reporting They are widened the same way for checking for best common super type and for reporting the error now. Previously error reporting forgot to widen and hit an assert. --- src/compiler/checker.ts | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 37163e9e8827b..a208487cdfead 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9624,6 +9624,7 @@ namespace ts { } } + Debug.assert(score < types.length, "types.length - 1 is the maximum score, given that getCommonSuperType returned false"); Debug.assert(!!downfallType, "If there is no common supertype, each type should have a downfallType"); if (score > bestSupertypeScore) { @@ -9632,7 +9633,6 @@ namespace ts { bestSupertypeScore = score; } - // types.length - 1 is the maximum score, given that getCommonSupertype returned false if (bestSupertypeScore === types.length - 1) { break; } @@ -10322,9 +10322,20 @@ namespace ts { return type.flags & TypeFlags.Union ? getUnionType(reducedTypes) : getIntersectionType(reducedTypes); } - function getInferenceCandidates(context: InferenceContext, index: number): Type[] { - const inferences = context.inferences[index]; - return inferences.primary || inferences.secondary || emptyArray; + /** + * We widen inferred literal types if + * all inferences were made to top-level ocurrences of the type parameter, and + * the type parameter has no constraint or its constraint includes no primitive or literal types, and + * the type parameter was fixed during inference or does not occur at top-level in the return type. + */ + function getInferenceCandidates(context: InferenceContext, index: number) { + const infier = context.inferences[index]; + const inferences = infier.primary || infier.secondary || emptyArray; + const signature = context.signature; + const widenLiteralTypes = infier.topLevel && + !hasPrimitiveConstraint(signature.typeParameters[index]) && + (infier.isFixed || !isTypeParameterAtTopLevel(getReturnTypeOfSignature(signature), signature.typeParameters[index])); + return widenLiteralTypes ? sameMap(inferences, getWidenedLiteralType) : inferences; } function hasPrimitiveConstraint(type: TypeParameter): boolean { @@ -10338,17 +10349,8 @@ namespace ts { if (!inferredType) { const inferences = getInferenceCandidates(context, index); if (inferences.length) { - // We widen inferred literal types if - // all inferences were made to top-level ocurrences of the type parameter, and - // the type parameter has no constraint or its constraint includes no primitive or literal types, and - // the type parameter was fixed during inference or does not occur at top-level in the return type. - const signature = context.signature; - const widenLiteralTypes = context.inferences[index].topLevel && - !hasPrimitiveConstraint(signature.typeParameters[index]) && - (context.inferences[index].isFixed || !isTypeParameterAtTopLevel(getReturnTypeOfSignature(signature), signature.typeParameters[index])); - const baseInferences = widenLiteralTypes ? sameMap(inferences, getWidenedLiteralType) : inferences; // Infer widened union or supertype, or the unknown type for no common supertype - const unionOrSuperType = context.inferUnionTypes ? getUnionType(baseInferences, /*subtypeReduction*/ true) : getCommonSupertype(baseInferences); + const unionOrSuperType = context.inferUnionTypes ? getUnionType(inferences, /*subtypeReduction*/ true) : getCommonSupertype(inferences); inferredType = unionOrSuperType ? getWidenedType(unionOrSuperType) : unknownType; inferenceSucceeded = !!unionOrSuperType; } From 862fa455bfeee02cf280d5fa424ef2f9eaa79b97 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Mon, 17 Apr 2017 08:28:10 -0700 Subject: [PATCH 02/11] Test widening inference candidates for err reports Add a test to show that error reporting for type inference widens the same way that type inference proper does. Previously it asserted. Also update other baselines with the widened type. --- ...erInSignatureWithRestParameters.errors.txt | 4 ++-- .../reference/genericRestArgs.errors.txt | 8 +++---- ...peTypeInferenceMatchesReporting.errors.txt | 22 +++++++++++++++++++ ...nSupertypeTypeInferenceMatchesReporting.js | 14 ++++++++++++ .../reference/parser15.4.4.14-9-2.errors.txt | 4 ++-- ...nSupertypeTypeInferenceMatchesReporting.ts | 7 ++++++ 6 files changed, 51 insertions(+), 8 deletions(-) create mode 100644 tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.errors.txt create mode 100644 tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.js create mode 100644 tests/cases/compiler/noCommonSupertypeTypeInferenceMatchesReporting.ts diff --git a/tests/baselines/reference/fixTypeParameterInSignatureWithRestParameters.errors.txt b/tests/baselines/reference/fixTypeParameterInSignatureWithRestParameters.errors.txt index e1cde0c163248..3666c89a0edd0 100644 --- a/tests/baselines/reference/fixTypeParameterInSignatureWithRestParameters.errors.txt +++ b/tests/baselines/reference/fixTypeParameterInSignatureWithRestParameters.errors.txt @@ -1,5 +1,5 @@ tests/cases/compiler/fixTypeParameterInSignatureWithRestParameters.ts(2,1): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. - Type argument candidate '1' is not a valid type argument because it is not a supertype of candidate '""'. + Type argument candidate 'number' is not a valid type argument because it is not a supertype of candidate 'string'. ==== tests/cases/compiler/fixTypeParameterInSignatureWithRestParameters.ts (1 errors) ==== @@ -7,4 +7,4 @@ tests/cases/compiler/fixTypeParameterInSignatureWithRestParameters.ts(2,1): erro bar(1, ""); // Should be ok ~~~ !!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. -!!! error TS2453: Type argument candidate '1' is not a valid type argument because it is not a supertype of candidate '""'. \ No newline at end of file +!!! error TS2453: Type argument candidate 'number' is not a valid type argument because it is not a supertype of candidate 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/genericRestArgs.errors.txt b/tests/baselines/reference/genericRestArgs.errors.txt index 2297277fe8d16..1dc8bd6f9779d 100644 --- a/tests/baselines/reference/genericRestArgs.errors.txt +++ b/tests/baselines/reference/genericRestArgs.errors.txt @@ -1,8 +1,8 @@ tests/cases/compiler/genericRestArgs.ts(2,12): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. - Type argument candidate '1' is not a valid type argument because it is not a supertype of candidate '""'. + Type argument candidate 'number' is not a valid type argument because it is not a supertype of candidate 'string'. tests/cases/compiler/genericRestArgs.ts(5,34): error TS2345: Argument of type '""' is not assignable to parameter of type 'number'. tests/cases/compiler/genericRestArgs.ts(10,12): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. - Type argument candidate '1' is not a valid type argument because it is not a supertype of candidate '""'. + Type argument candidate 'number' is not a valid type argument because it is not a supertype of candidate 'string'. tests/cases/compiler/genericRestArgs.ts(12,30): error TS2345: Argument of type '1' is not assignable to parameter of type 'any[]'. @@ -11,7 +11,7 @@ tests/cases/compiler/genericRestArgs.ts(12,30): error TS2345: Argument of type ' var a1Ga = makeArrayG(1, ""); // no error ~~~~~~~~~~ !!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. -!!! error TS2453: Type argument candidate '1' is not a valid type argument because it is not a supertype of candidate '""'. +!!! error TS2453: Type argument candidate 'number' is not a valid type argument because it is not a supertype of candidate 'string'. var a1Gb = makeArrayG(1, ""); var a1Gc = makeArrayG(1, ""); var a1Gd = makeArrayG(1, ""); // error @@ -24,7 +24,7 @@ tests/cases/compiler/genericRestArgs.ts(12,30): error TS2345: Argument of type ' var a2Ga = makeArrayGOpt(1, ""); ~~~~~~~~~~~~~ !!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. -!!! error TS2453: Type argument candidate '1' is not a valid type argument because it is not a supertype of candidate '""'. +!!! error TS2453: Type argument candidate 'number' is not a valid type argument because it is not a supertype of candidate 'string'. var a2Gb = makeArrayG(1, ""); var a2Gc = makeArrayG(1, ""); // error ~ diff --git a/tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.errors.txt b/tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.errors.txt new file mode 100644 index 0000000000000..1db0f3e7c6c5c --- /dev/null +++ b/tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.errors.txt @@ -0,0 +1,22 @@ +tests/cases/compiler/noCommonSupertypeTypeInferenceMatchesReporting.ts(4,5): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. + Type argument candidate '12 | undefined' is not a valid type argument because it is not a supertype of candidate 'number'. +tests/cases/compiler/noCommonSupertypeTypeInferenceMatchesReporting.ts(5,5): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. + Type argument candidate 'number' is not a valid type argument because it is not a supertype of candidate '12 | undefined'. + Type 'undefined' is not assignable to type 'number'. + + +==== tests/cases/compiler/noCommonSupertypeTypeInferenceMatchesReporting.ts (2 errors) ==== + // Fixes #15116, which asserted on line 5 but not 6 + declare function f(a: T, b: T): boolean; + function g(gut: { n: 12 | undefined }) { + f(gut.n, 12); // error, no common supertype + ~ +!!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. +!!! error TS2453: Type argument candidate '12 | undefined' is not a valid type argument because it is not a supertype of candidate 'number'. + f(12, gut.n); // error, no common supertype + ~ +!!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. +!!! error TS2453: Type argument candidate 'number' is not a valid type argument because it is not a supertype of candidate '12 | undefined'. +!!! error TS2453: Type 'undefined' is not assignable to type 'number'. + } + \ No newline at end of file diff --git a/tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.js b/tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.js new file mode 100644 index 0000000000000..1ef1ca7dfb924 --- /dev/null +++ b/tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.js @@ -0,0 +1,14 @@ +//// [noCommonSupertypeTypeInferenceMatchesReporting.ts] +// Fixes #15116, which asserted on line 5 but not 6 +declare function f(a: T, b: T): boolean; +function g(gut: { n: 12 | undefined }) { + f(gut.n, 12); // error, no common supertype + f(12, gut.n); // error, no common supertype +} + + +//// [noCommonSupertypeTypeInferenceMatchesReporting.js] +function g(gut) { + f(gut.n, 12); // error, no common supertype + f(12, gut.n); // error, no common supertype +} diff --git a/tests/baselines/reference/parser15.4.4.14-9-2.errors.txt b/tests/baselines/reference/parser15.4.4.14-9-2.errors.txt index 2c721724b3e76..48484e6917c3f 100644 --- a/tests/baselines/reference/parser15.4.4.14-9-2.errors.txt +++ b/tests/baselines/reference/parser15.4.4.14-9-2.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/parser/ecmascript5/parser15.4.4.14-9-2.ts(16,15): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. - Type argument candidate 'number' is not a valid type argument because it is not a supertype of candidate 'false'. + Type argument candidate 'number' is not a valid type argument because it is not a supertype of candidate 'boolean'. tests/cases/conformance/parser/ecmascript5/parser15.4.4.14-9-2.ts(25,1): error TS2304: Cannot find name 'runTestCase'. @@ -22,7 +22,7 @@ tests/cases/conformance/parser/ecmascript5/parser15.4.4.14-9-2.ts(25,1): error T var a = new Array(false,undefined,null,"0",obj,-1.3333333333333, "str",-0,true,+0, one, 1,0, false, _float, -(4/3)); ~~~~~ !!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. -!!! error TS2453: Type argument candidate 'number' is not a valid type argument because it is not a supertype of candidate 'false'. +!!! error TS2453: Type argument candidate 'number' is not a valid type argument because it is not a supertype of candidate 'boolean'. if (a.indexOf(-(4/3)) === 14 && // a[14]=_float===-(4/3) a.indexOf(0) === 7 && // a[7] = +0, 0===+0 a.indexOf(-0) === 7 && // a[7] = +0, -0===+0 diff --git a/tests/cases/compiler/noCommonSupertypeTypeInferenceMatchesReporting.ts b/tests/cases/compiler/noCommonSupertypeTypeInferenceMatchesReporting.ts new file mode 100644 index 0000000000000..60834d82d36b3 --- /dev/null +++ b/tests/cases/compiler/noCommonSupertypeTypeInferenceMatchesReporting.ts @@ -0,0 +1,7 @@ +// @strictNullChecks: true +// Fixes #15116, which asserted on line 5 but not 6 +declare function f(a: T, b: T): boolean; +function g(gut: { n: 12 | undefined }) { + f(gut.n, 12); // error, no common supertype + f(12, gut.n); // error, no common supertype +} From 8486b612cab212bed3bedcb21fc45396ee5be067 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Mon, 17 Apr 2017 08:34:30 -0700 Subject: [PATCH 03/11] Policheck made-up Romance words and improve types --- src/compiler/checker.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a208487cdfead..90fe73c0a3de7 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10329,12 +10329,12 @@ namespace ts { * the type parameter was fixed during inference or does not occur at top-level in the return type. */ function getInferenceCandidates(context: InferenceContext, index: number) { - const infier = context.inferences[index]; - const inferences = infier.primary || infier.secondary || emptyArray; + const typeInferences = context.inferences[index]; + const inferences: Type[] = typeInferences.primary || typeInferences.secondary || emptyArray; const signature = context.signature; - const widenLiteralTypes = infier.topLevel && + const widenLiteralTypes = typeInferences.topLevel && !hasPrimitiveConstraint(signature.typeParameters[index]) && - (infier.isFixed || !isTypeParameterAtTopLevel(getReturnTypeOfSignature(signature), signature.typeParameters[index])); + (typeInferences.isFixed || !isTypeParameterAtTopLevel(getReturnTypeOfSignature(signature), signature.typeParameters[index])); return widenLiteralTypes ? sameMap(inferences, getWidenedLiteralType) : inferences; } From 3541c38a750977d22361aa0bb96a797b85f339d2 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Mon, 17 Apr 2017 13:39:47 -0700 Subject: [PATCH 04/11] getCommonSupertype correctly widens unions Previously it discarded and re-added *top-level* nulls and undefineds in the inference candidate list. Which doesn't make much sense. Now it discards and re-adds nulls and undefineds that are unioned with types in the inference candidate list. This makes the new test pass now instead of failing. --- src/compiler/checker.ts | 8 ++--- ...peTypeInferenceMatchesReporting.errors.txt | 22 ------------- ...rtypeTypeInferenceMatchesReporting.symbols | 28 ++++++++++++++++ ...pertypeTypeInferenceMatchesReporting.types | 32 +++++++++++++++++++ 4 files changed, 62 insertions(+), 28 deletions(-) delete mode 100644 tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.errors.txt create mode 100644 tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.symbols create mode 100644 tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.types diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 90fe73c0a3de7..c40ddb2cfcb8c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9596,12 +9596,8 @@ namespace ts { if (!strictNullChecks) { return getSupertypeOrUnion(types); } - const primaryTypes = filter(types, t => !(t.flags & TypeFlags.Nullable)); - if (!primaryTypes.length) { - return getUnionType(types, /*subtypeReduction*/ true); - } - const supertype = getSupertypeOrUnion(primaryTypes); - return supertype && includeFalsyTypes(supertype, getFalsyFlagsOfTypes(types) & TypeFlags.Nullable); + const supertype = getSupertypeOrUnion(map(types, getNonNullableType)); + return supertype && includeFalsyTypes(supertype, getFalsyFlagsOfTypes(types) & (TypeFlags.Nullable | TypeFlags.Void)); } function reportNoCommonSupertypeError(types: Type[], errorLocation: Node, errorMessageChainHead: DiagnosticMessageChain): void { diff --git a/tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.errors.txt b/tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.errors.txt deleted file mode 100644 index 1db0f3e7c6c5c..0000000000000 --- a/tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.errors.txt +++ /dev/null @@ -1,22 +0,0 @@ -tests/cases/compiler/noCommonSupertypeTypeInferenceMatchesReporting.ts(4,5): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. - Type argument candidate '12 | undefined' is not a valid type argument because it is not a supertype of candidate 'number'. -tests/cases/compiler/noCommonSupertypeTypeInferenceMatchesReporting.ts(5,5): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. - Type argument candidate 'number' is not a valid type argument because it is not a supertype of candidate '12 | undefined'. - Type 'undefined' is not assignable to type 'number'. - - -==== tests/cases/compiler/noCommonSupertypeTypeInferenceMatchesReporting.ts (2 errors) ==== - // Fixes #15116, which asserted on line 5 but not 6 - declare function f(a: T, b: T): boolean; - function g(gut: { n: 12 | undefined }) { - f(gut.n, 12); // error, no common supertype - ~ -!!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. -!!! error TS2453: Type argument candidate '12 | undefined' is not a valid type argument because it is not a supertype of candidate 'number'. - f(12, gut.n); // error, no common supertype - ~ -!!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. -!!! error TS2453: Type argument candidate 'number' is not a valid type argument because it is not a supertype of candidate '12 | undefined'. -!!! error TS2453: Type 'undefined' is not assignable to type 'number'. - } - \ No newline at end of file diff --git a/tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.symbols b/tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.symbols new file mode 100644 index 0000000000000..747d0494f93e3 --- /dev/null +++ b/tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.symbols @@ -0,0 +1,28 @@ +=== tests/cases/compiler/noCommonSupertypeTypeInferenceMatchesReporting.ts === +// Fixes #15116, which asserted on line 5 but not 6 +declare function f(a: T, b: T): boolean; +>f : Symbol(f, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 0, 0)) +>T : Symbol(T, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 1, 19)) +>a : Symbol(a, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 1, 22)) +>T : Symbol(T, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 1, 19)) +>b : Symbol(b, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 1, 27)) +>T : Symbol(T, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 1, 19)) + +function g(gut: { n: 12 | undefined }) { +>g : Symbol(g, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 1, 43)) +>gut : Symbol(gut, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 2, 11)) +>n : Symbol(n, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 2, 17)) + + f(gut.n, 12); // error, no common supertype +>f : Symbol(f, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 0, 0)) +>gut.n : Symbol(n, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 2, 17)) +>gut : Symbol(gut, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 2, 11)) +>n : Symbol(n, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 2, 17)) + + f(12, gut.n); // error, no common supertype +>f : Symbol(f, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 0, 0)) +>gut.n : Symbol(n, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 2, 17)) +>gut : Symbol(gut, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 2, 11)) +>n : Symbol(n, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 2, 17)) +} + diff --git a/tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.types b/tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.types new file mode 100644 index 0000000000000..62ab0f2e9172f --- /dev/null +++ b/tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.types @@ -0,0 +1,32 @@ +=== tests/cases/compiler/noCommonSupertypeTypeInferenceMatchesReporting.ts === +// Fixes #15116, which asserted on line 5 but not 6 +declare function f(a: T, b: T): boolean; +>f : (a: T, b: T) => boolean +>T : T +>a : T +>T : T +>b : T +>T : T + +function g(gut: { n: 12 | undefined }) { +>g : (gut: { n: 12 | undefined; }) => void +>gut : { n: 12 | undefined; } +>n : 12 | undefined + + f(gut.n, 12); // error, no common supertype +>f(gut.n, 12) : boolean +>f : (a: T, b: T) => boolean +>gut.n : 12 | undefined +>gut : { n: 12 | undefined; } +>n : 12 | undefined +>12 : 12 + + f(12, gut.n); // error, no common supertype +>f(12, gut.n) : boolean +>f : (a: T, b: T) => boolean +>12 : 12 +>gut.n : 12 | undefined +>gut : { n: 12 | undefined; } +>n : 12 | undefined +} + From 806739524e351aa68f1946237502df78e41a6eb3 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Mon, 17 Apr 2017 13:43:21 -0700 Subject: [PATCH 05/11] Update test comments --- .../noCommonSupertypeTypeInferenceMatchesReporting.js | 8 ++++---- ...noCommonSupertypeTypeInferenceMatchesReporting.symbols | 4 ++-- .../noCommonSupertypeTypeInferenceMatchesReporting.types | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.js b/tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.js index 1ef1ca7dfb924..b198635f81730 100644 --- a/tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.js +++ b/tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.js @@ -2,13 +2,13 @@ // Fixes #15116, which asserted on line 5 but not 6 declare function f(a: T, b: T): boolean; function g(gut: { n: 12 | undefined }) { - f(gut.n, 12); // error, no common supertype - f(12, gut.n); // error, no common supertype + f(gut.n, 12); // ok, T = number | undefined + f(12, gut.n); // ok, T = number | undefined } //// [noCommonSupertypeTypeInferenceMatchesReporting.js] function g(gut) { - f(gut.n, 12); // error, no common supertype - f(12, gut.n); // error, no common supertype + f(gut.n, 12); // ok, T = number | undefined + f(12, gut.n); // ok, T = number | undefined } diff --git a/tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.symbols b/tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.symbols index 747d0494f93e3..43a22192746b8 100644 --- a/tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.symbols +++ b/tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.symbols @@ -13,13 +13,13 @@ function g(gut: { n: 12 | undefined }) { >gut : Symbol(gut, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 2, 11)) >n : Symbol(n, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 2, 17)) - f(gut.n, 12); // error, no common supertype + f(gut.n, 12); // ok, T = number | undefined >f : Symbol(f, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 0, 0)) >gut.n : Symbol(n, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 2, 17)) >gut : Symbol(gut, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 2, 11)) >n : Symbol(n, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 2, 17)) - f(12, gut.n); // error, no common supertype + f(12, gut.n); // ok, T = number | undefined >f : Symbol(f, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 0, 0)) >gut.n : Symbol(n, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 2, 17)) >gut : Symbol(gut, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 2, 11)) diff --git a/tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.types b/tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.types index 62ab0f2e9172f..8cee7d8d60f8b 100644 --- a/tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.types +++ b/tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.types @@ -13,7 +13,7 @@ function g(gut: { n: 12 | undefined }) { >gut : { n: 12 | undefined; } >n : 12 | undefined - f(gut.n, 12); // error, no common supertype + f(gut.n, 12); // ok, T = number | undefined >f(gut.n, 12) : boolean >f : (a: T, b: T) => boolean >gut.n : 12 | undefined @@ -21,7 +21,7 @@ function g(gut: { n: 12 | undefined }) { >n : 12 | undefined >12 : 12 - f(12, gut.n); // error, no common supertype + f(12, gut.n); // ok, T = number | undefined >f(12, gut.n) : boolean >f : (a: T, b: T) => boolean >12 : 12 From 502803ae748ce30c90d38f6ef1e4283c5da52fb3 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Mon, 17 Apr 2017 13:51:41 -0700 Subject: [PATCH 06/11] Update test too. Previous commit mistakenly only updated baselines --- .../noCommonSupertypeTypeInferenceMatchesReporting.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/cases/compiler/noCommonSupertypeTypeInferenceMatchesReporting.ts b/tests/cases/compiler/noCommonSupertypeTypeInferenceMatchesReporting.ts index 60834d82d36b3..d0c6b1360d809 100644 --- a/tests/cases/compiler/noCommonSupertypeTypeInferenceMatchesReporting.ts +++ b/tests/cases/compiler/noCommonSupertypeTypeInferenceMatchesReporting.ts @@ -2,6 +2,6 @@ // Fixes #15116, which asserted on line 5 but not 6 declare function f(a: T, b: T): boolean; function g(gut: { n: 12 | undefined }) { - f(gut.n, 12); // error, no common supertype - f(12, gut.n); // error, no common supertype + f(gut.n, 12); // ok, T = number | undefined + f(12, gut.n); // ok, T = number | undefined } From f56fe9ebe7ac6f67d29512afe3b96b48f228cac7 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 19 Apr 2017 08:56:34 -0700 Subject: [PATCH 07/11] Improve new assert in reportNoCommonSupertypeError --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c40ddb2cfcb8c..7c098183bd0c0 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9620,7 +9620,6 @@ namespace ts { } } - Debug.assert(score < types.length, "types.length - 1 is the maximum score, given that getCommonSuperType returned false"); Debug.assert(!!downfallType, "If there is no common supertype, each type should have a downfallType"); if (score > bestSupertypeScore) { @@ -9629,6 +9628,7 @@ namespace ts { bestSupertypeScore = score; } + Debug.assert(bestSupertypeScore < types.length, "types.length - 1 is the maximum score, given that getCommonSuperType returned false"); if (bestSupertypeScore === types.length - 1) { break; } From db3d88ea5f06dd59c1962976963ffdafd9fa2b0b Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Thu, 8 Jun 2017 10:46:44 -0700 Subject: [PATCH 08/11] getNullableType supports void Add getOptionalType to support the common case of just adding undefined. --- src/compiler/checker.ts | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1ce3b97977e7f..014c807650883 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2854,7 +2854,7 @@ namespace ts { let parameterType = getTypeOfSymbol(parameterSymbol); if (isRequiredInitializedParameter(parameterDeclaration)) { - parameterType = getNullableType(parameterType, TypeFlags.Undefined); + parameterType = getOptionalType(parameterType); } const parameterTypeNode = typeToTypeNodeHelper(parameterType, context); @@ -3619,7 +3619,7 @@ namespace ts { let type = getTypeOfSymbol(p); if (parameterNode && isRequiredInitializedParameter(parameterNode)) { - type = getNullableType(type, TypeFlags.Undefined); + type = getOptionalType(type); } buildTypeDisplay(type, writer, enclosingDeclaration, flags, symbolStack); } @@ -4195,7 +4195,7 @@ namespace ts { } function addOptionality(type: Type, optional: boolean): Type { - return strictNullChecks && optional ? getNullableType(type, TypeFlags.Undefined) : type; + return strictNullChecks && optional ? getOptionalType(type) : type; } // Return the inferred type for a variable, parameter, or property declaration @@ -4622,7 +4622,7 @@ namespace ts { links.type = baseTypeVariable ? getIntersectionType([type, baseTypeVariable]) : type; } else { - links.type = strictNullChecks && symbol.flags & SymbolFlags.Optional ? getNullableType(type, TypeFlags.Undefined) : type; + links.type = strictNullChecks && symbol.flags & SymbolFlags.Optional ? getOptionalType(type) : type; } } } @@ -10019,12 +10019,21 @@ namespace ts { neverType; } + /** Add undefined to a type */ + function getOptionalType(type: Type): Type { + return type.flags & TypeFlags.Undefined ? type : getUnionType([type, undefinedType]); + } + + /** Add undefined, null or void to a type as requested by flags */ function getNullableType(type: Type, flags: TypeFlags): Type { - const missing = (flags & ~type.flags) & (TypeFlags.Undefined | TypeFlags.Null); - return missing === 0 ? type : - missing === TypeFlags.Undefined ? getUnionType([type, undefinedType]) : - missing === TypeFlags.Null ? getUnionType([type, nullType]) : - getUnionType([type, undefinedType, nullType]); + if ((getFalsyFlags(type) & flags) === flags) { + return type; + } + const types = [type]; + if (flags & TypeFlags.Void) types.push(voidType); + if (flags & TypeFlags.Undefined) types.push(undefinedType); + if (flags & TypeFlags.Null) types.push(nullType); + return getUnionType(types); } function getNonNullableType(type: Type): Type { @@ -12153,7 +12162,7 @@ namespace ts { isInAmbientContext(declaration); const initialType = assumeInitialized ? (isParameter ? removeOptionalityFromDeclaredType(type, getRootDeclaration(declaration) as VariableLikeDeclaration) : type) : type === autoType || type === autoArrayType ? undefinedType : - getNullableType(type, TypeFlags.Undefined); + getOptionalType(type); const flowType = getFlowTypeOfReference(node, type, initialType, flowContainer, !assumeInitialized); // A variable is considered uninitialized when it is possible to analyze the entire control flow graph // from declaration to use, and when the variable's declared type doesn't include undefined but the @@ -16342,7 +16351,7 @@ namespace ts { if (strictNullChecks) { const declaration = symbol.valueDeclaration; if (declaration && (declaration).initializer) { - return getNullableType(type, TypeFlags.Undefined); + return getOptionalType(type); } } return type; @@ -23249,7 +23258,7 @@ namespace ts { ? getWidenedLiteralType(getTypeOfSymbol(symbol)) : unknownType; if (flags & TypeFormatFlags.AddUndefined) { - type = getNullableType(type, TypeFlags.Undefined); + type = getOptionalType(type); } getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags); } From 637581b46c3f1f585a54095f485af80e514fad14 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Thu, 8 Jun 2017 10:54:57 -0700 Subject: [PATCH 09/11] Fix semicolon lint --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 014c807650883..300d53a0b2b1b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10660,7 +10660,7 @@ namespace ts { let inferenceSucceeded: boolean; if (!inferredType) { if (inference.candidates) { - const baseCandidates = widenInferenceCandidates(inference, context.signature) + const baseCandidates = widenInferenceCandidates(inference, context.signature); // Infer widened union or supertype, or the unknown type for no common supertype. We infer union types // for inferences coming from return types in order to avoid common supertype failures. const unionOrSuperType = context.flags & InferenceFlags.InferUnionTypes || inference.priority & InferencePriority.ReturnType ? From ec9e2808dacbb2f0aecb1504ec1dfd00e1053b43 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Fri, 9 Jun 2017 15:09:07 -0700 Subject: [PATCH 10/11] Restore getNullableType and getCommonSupertype This changes the new test's baseline. Note that the new test exists to show that the compiler no longer crashes, so errors are fine. --- src/compiler/checker.ts | 41 ++++++++----------- ...peTypeInferenceMatchesReporting.errors.txt | 22 ++++++++++ ...rtypeTypeInferenceMatchesReporting.symbols | 28 ------------- ...pertypeTypeInferenceMatchesReporting.types | 32 --------------- 4 files changed, 40 insertions(+), 83 deletions(-) create mode 100644 tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.errors.txt delete mode 100644 tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.symbols delete mode 100644 tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.types diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 300d53a0b2b1b..5ef722f40778b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2854,7 +2854,7 @@ namespace ts { let parameterType = getTypeOfSymbol(parameterSymbol); if (isRequiredInitializedParameter(parameterDeclaration)) { - parameterType = getOptionalType(parameterType); + parameterType = getNullableType(parameterType, TypeFlags.Undefined); } const parameterTypeNode = typeToTypeNodeHelper(parameterType, context); @@ -3619,7 +3619,7 @@ namespace ts { let type = getTypeOfSymbol(p); if (parameterNode && isRequiredInitializedParameter(parameterNode)) { - type = getOptionalType(type); + type = getNullableType(type, TypeFlags.Undefined); } buildTypeDisplay(type, writer, enclosingDeclaration, flags, symbolStack); } @@ -4195,7 +4195,7 @@ namespace ts { } function addOptionality(type: Type, optional: boolean): Type { - return strictNullChecks && optional ? getOptionalType(type) : type; + return strictNullChecks && optional ? getNullableType(type, TypeFlags.Undefined) : type; } // Return the inferred type for a variable, parameter, or property declaration @@ -4622,7 +4622,7 @@ namespace ts { links.type = baseTypeVariable ? getIntersectionType([type, baseTypeVariable]) : type; } else { - links.type = strictNullChecks && symbol.flags & SymbolFlags.Optional ? getOptionalType(type) : type; + links.type = strictNullChecks && symbol.flags & SymbolFlags.Optional ? getNullableType(type, TypeFlags.Undefined) : type; } } } @@ -9884,8 +9884,12 @@ namespace ts { if (!strictNullChecks) { return getSupertypeOrUnion(types); } - const supertype = getSupertypeOrUnion(map(types, getNonNullableType)); - return supertype && getNullableType(supertype, getFalsyFlagsOfTypes(types) & (TypeFlags.Nullable | TypeFlags.Void)); + const primaryTypes = filter(types, t => !(t.flags & TypeFlags.Nullable)); + if (!primaryTypes.length) { + return getUnionType(types, /*subtypeReduction*/ true); + } + const supertype = getSupertypeOrUnion(primaryTypes); + return supertype && getNullableType(supertype, getFalsyFlagsOfTypes(types) & TypeFlags.Nullable); } function reportNoCommonSupertypeError(types: Type[], errorLocation: Node, errorMessageChainHead: DiagnosticMessageChain): void { @@ -10019,21 +10023,12 @@ namespace ts { neverType; } - /** Add undefined to a type */ - function getOptionalType(type: Type): Type { - return type.flags & TypeFlags.Undefined ? type : getUnionType([type, undefinedType]); - } - - /** Add undefined, null or void to a type as requested by flags */ function getNullableType(type: Type, flags: TypeFlags): Type { - if ((getFalsyFlags(type) & flags) === flags) { - return type; - } - const types = [type]; - if (flags & TypeFlags.Void) types.push(voidType); - if (flags & TypeFlags.Undefined) types.push(undefinedType); - if (flags & TypeFlags.Null) types.push(nullType); - return getUnionType(types); + const missing = (flags & ~type.flags) & (TypeFlags.Undefined | TypeFlags.Null); + return missing === 0 ? type : + missing === TypeFlags.Undefined ? getUnionType([type, undefinedType]) : + missing === TypeFlags.Null ? getUnionType([type, nullType]) : + getUnionType([type, undefinedType, nullType]); } function getNonNullableType(type: Type): Type { @@ -12162,7 +12157,7 @@ namespace ts { isInAmbientContext(declaration); const initialType = assumeInitialized ? (isParameter ? removeOptionalityFromDeclaredType(type, getRootDeclaration(declaration) as VariableLikeDeclaration) : type) : type === autoType || type === autoArrayType ? undefinedType : - getOptionalType(type); + getNullableType(type, TypeFlags.Undefined); const flowType = getFlowTypeOfReference(node, type, initialType, flowContainer, !assumeInitialized); // A variable is considered uninitialized when it is possible to analyze the entire control flow graph // from declaration to use, and when the variable's declared type doesn't include undefined but the @@ -16351,7 +16346,7 @@ namespace ts { if (strictNullChecks) { const declaration = symbol.valueDeclaration; if (declaration && (declaration).initializer) { - return getOptionalType(type); + return getNullableType(type, TypeFlags.Undefined); } } return type; @@ -23258,7 +23253,7 @@ namespace ts { ? getWidenedLiteralType(getTypeOfSymbol(symbol)) : unknownType; if (flags & TypeFormatFlags.AddUndefined) { - type = getOptionalType(type); + type = getNullableType(type, TypeFlags.Undefined); } getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags); } diff --git a/tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.errors.txt b/tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.errors.txt new file mode 100644 index 0000000000000..58b3f502953f9 --- /dev/null +++ b/tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.errors.txt @@ -0,0 +1,22 @@ +tests/cases/compiler/noCommonSupertypeTypeInferenceMatchesReporting.ts(4,5): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. + Type argument candidate '12 | undefined' is not a valid type argument because it is not a supertype of candidate 'number'. +tests/cases/compiler/noCommonSupertypeTypeInferenceMatchesReporting.ts(5,5): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. + Type argument candidate 'number' is not a valid type argument because it is not a supertype of candidate '12 | undefined'. + Type 'undefined' is not assignable to type 'number'. + + +==== tests/cases/compiler/noCommonSupertypeTypeInferenceMatchesReporting.ts (2 errors) ==== + // Fixes #15116, which asserted on line 5 but not 6 + declare function f(a: T, b: T): boolean; + function g(gut: { n: 12 | undefined }) { + f(gut.n, 12); // ok, T = number | undefined + ~ +!!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. +!!! error TS2453: Type argument candidate '12 | undefined' is not a valid type argument because it is not a supertype of candidate 'number'. + f(12, gut.n); // ok, T = number | undefined + ~ +!!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. +!!! error TS2453: Type argument candidate 'number' is not a valid type argument because it is not a supertype of candidate '12 | undefined'. +!!! error TS2453: Type 'undefined' is not assignable to type 'number'. + } + \ No newline at end of file diff --git a/tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.symbols b/tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.symbols deleted file mode 100644 index 43a22192746b8..0000000000000 --- a/tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.symbols +++ /dev/null @@ -1,28 +0,0 @@ -=== tests/cases/compiler/noCommonSupertypeTypeInferenceMatchesReporting.ts === -// Fixes #15116, which asserted on line 5 but not 6 -declare function f(a: T, b: T): boolean; ->f : Symbol(f, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 0, 0)) ->T : Symbol(T, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 1, 19)) ->a : Symbol(a, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 1, 22)) ->T : Symbol(T, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 1, 19)) ->b : Symbol(b, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 1, 27)) ->T : Symbol(T, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 1, 19)) - -function g(gut: { n: 12 | undefined }) { ->g : Symbol(g, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 1, 43)) ->gut : Symbol(gut, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 2, 11)) ->n : Symbol(n, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 2, 17)) - - f(gut.n, 12); // ok, T = number | undefined ->f : Symbol(f, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 0, 0)) ->gut.n : Symbol(n, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 2, 17)) ->gut : Symbol(gut, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 2, 11)) ->n : Symbol(n, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 2, 17)) - - f(12, gut.n); // ok, T = number | undefined ->f : Symbol(f, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 0, 0)) ->gut.n : Symbol(n, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 2, 17)) ->gut : Symbol(gut, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 2, 11)) ->n : Symbol(n, Decl(noCommonSupertypeTypeInferenceMatchesReporting.ts, 2, 17)) -} - diff --git a/tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.types b/tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.types deleted file mode 100644 index 8cee7d8d60f8b..0000000000000 --- a/tests/baselines/reference/noCommonSupertypeTypeInferenceMatchesReporting.types +++ /dev/null @@ -1,32 +0,0 @@ -=== tests/cases/compiler/noCommonSupertypeTypeInferenceMatchesReporting.ts === -// Fixes #15116, which asserted on line 5 but not 6 -declare function f(a: T, b: T): boolean; ->f : (a: T, b: T) => boolean ->T : T ->a : T ->T : T ->b : T ->T : T - -function g(gut: { n: 12 | undefined }) { ->g : (gut: { n: 12 | undefined; }) => void ->gut : { n: 12 | undefined; } ->n : 12 | undefined - - f(gut.n, 12); // ok, T = number | undefined ->f(gut.n, 12) : boolean ->f : (a: T, b: T) => boolean ->gut.n : 12 | undefined ->gut : { n: 12 | undefined; } ->n : 12 | undefined ->12 : 12 - - f(12, gut.n); // ok, T = number | undefined ->f(12, gut.n) : boolean ->f : (a: T, b: T) => boolean ->12 : 12 ->gut.n : 12 | undefined ->gut : { n: 12 | undefined; } ->n : 12 | undefined -} - From bf4961ba7a9e0faf4e1f8d9a55ffc6ed97eea09f Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Fri, 9 Jun 2017 15:10:21 -0700 Subject: [PATCH 11/11] Fix indentation --- src/compiler/checker.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5ef722f40778b..3109aec227e84 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10025,10 +10025,10 @@ namespace ts { function getNullableType(type: Type, flags: TypeFlags): Type { const missing = (flags & ~type.flags) & (TypeFlags.Undefined | TypeFlags.Null); - return missing === 0 ? type : - missing === TypeFlags.Undefined ? getUnionType([type, undefinedType]) : - missing === TypeFlags.Null ? getUnionType([type, nullType]) : - getUnionType([type, undefinedType, nullType]); + return missing === 0 ? type : + missing === TypeFlags.Undefined ? getUnionType([type, undefinedType]) : + missing === TypeFlags.Null ? getUnionType([type, nullType]) : + getUnionType([type, undefinedType, nullType]); } function getNonNullableType(type: Type): Type {