No subtype reduction in includeFalsyTypes

It's not really needed and caused #13826.
This commit is contained in:
Nathan Shively-Sanders 2017-02-07 09:47:10 -08:00
parent 94aeff2a2c
commit e03509affa
5 changed files with 78 additions and 1 deletions

View file

@ -8540,7 +8540,7 @@ namespace ts {
if (flags & TypeFlags.Void) types.push(voidType);
if (flags & TypeFlags.Undefined) types.push(undefinedType);
if (flags & TypeFlags.Null) types.push(nullType);
return getUnionType(types, /*subtypeReduction*/ true);
return getUnionType(types);
}
function removeDefinitelyFalsyTypes(type: Type): Type {

View file

@ -0,0 +1,14 @@
//// [optionalParameterRetainsNull.ts]
interface Bar { bar: number; foo: object | null; }
let a = {
test<K extends keyof Bar> (a: K, b?: Bar[K] | null) { }
};
a.test("bar", null); // ok, null is assignable to number | null | undefined
//// [optionalParameterRetainsNull.js]
var a = {
test: function (a, b) { }
};
a.test("bar", null); // ok, null is assignable to number | null | undefined

View file

@ -0,0 +1,25 @@
=== tests/cases/compiler/optionalParameterRetainsNull.ts ===
interface Bar { bar: number; foo: object | null; }
>Bar : Symbol(Bar, Decl(optionalParameterRetainsNull.ts, 0, 0))
>bar : Symbol(Bar.bar, Decl(optionalParameterRetainsNull.ts, 0, 15))
>foo : Symbol(Bar.foo, Decl(optionalParameterRetainsNull.ts, 0, 29))
let a = {
>a : Symbol(a, Decl(optionalParameterRetainsNull.ts, 2, 3))
test<K extends keyof Bar> (a: K, b?: Bar[K] | null) { }
>test : Symbol(test, Decl(optionalParameterRetainsNull.ts, 2, 9))
>K : Symbol(K, Decl(optionalParameterRetainsNull.ts, 3, 7))
>Bar : Symbol(Bar, Decl(optionalParameterRetainsNull.ts, 0, 0))
>a : Symbol(a, Decl(optionalParameterRetainsNull.ts, 3, 29))
>K : Symbol(K, Decl(optionalParameterRetainsNull.ts, 3, 7))
>b : Symbol(b, Decl(optionalParameterRetainsNull.ts, 3, 34))
>Bar : Symbol(Bar, Decl(optionalParameterRetainsNull.ts, 0, 0))
>K : Symbol(K, Decl(optionalParameterRetainsNull.ts, 3, 7))
};
a.test("bar", null); // ok, null is assignable to number | null | undefined
>a.test : Symbol(test, Decl(optionalParameterRetainsNull.ts, 2, 9))
>a : Symbol(a, Decl(optionalParameterRetainsNull.ts, 2, 3))
>test : Symbol(test, Decl(optionalParameterRetainsNull.ts, 2, 9))

View file

@ -0,0 +1,31 @@
=== tests/cases/compiler/optionalParameterRetainsNull.ts ===
interface Bar { bar: number; foo: object | null; }
>Bar : Bar
>bar : number
>foo : object | null
>null : null
let a = {
>a : { test<K extends "bar" | "foo">(a: K, b?: Bar[K] | null | undefined): void; }
>{ test<K extends keyof Bar> (a: K, b?: Bar[K] | null) { }} : { test<K extends "bar" | "foo">(a: K, b?: Bar[K] | null | undefined): void; }
test<K extends keyof Bar> (a: K, b?: Bar[K] | null) { }
>test : <K extends "bar" | "foo">(a: K, b?: Bar[K] | null | undefined) => void
>K : K
>Bar : Bar
>a : K
>K : K
>b : Bar[K] | null | undefined
>Bar : Bar
>K : K
>null : null
};
a.test("bar", null); // ok, null is assignable to number | null | undefined
>a.test("bar", null) : void
>a.test : <K extends "bar" | "foo">(a: K, b?: Bar[K] | null | undefined) => void
>a : { test<K extends "bar" | "foo">(a: K, b?: Bar[K] | null | undefined): void; }
>test : <K extends "bar" | "foo">(a: K, b?: Bar[K] | null | undefined) => void
>"bar" : "bar"
>null : null

View file

@ -0,0 +1,7 @@
// @strictNullChecks: true
interface Bar { bar: number; foo: object | null; }
let a = {
test<K extends keyof Bar> (a: K, b?: Bar[K] | null) { }
};
a.test("bar", null); // ok, null is assignable to number | null | undefined