Skip to content

Commit

Permalink
Update test file and baselines
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-williams committed Sep 18, 2018
1 parent 59ceddb commit a8cc939
Show file tree
Hide file tree
Showing 5 changed files with 567 additions and 39 deletions.
10 changes: 8 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15014,8 +15014,14 @@ namespace ts {
assumeTrue = !assumeTrue;
}
const valueType = getTypeOfExpression(value);
if ((type.flags & TypeFlags.Unknown) && (operator === SyntaxKind.EqualsEqualsEqualsToken) && (valueType.flags & TypeFlags.Unit)) {
return assumeTrue ? valueType : type;
if ((type.flags & TypeFlags.Unknown) && (operator === SyntaxKind.EqualsEqualsEqualsToken) && assumeTrue) {
if (valueType.flags & (TypeFlags.Primitive | TypeFlags.NonPrimitive)) {
return valueType;
}
if (valueType.flags & TypeFlags.Object) {
return nonPrimitiveType;
}
return type;
}
if (valueType.flags & TypeFlags.Nullable) {
if (!strictNullChecks) {
Expand Down
123 changes: 115 additions & 8 deletions tests/baselines/reference/unknownType2.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if (u === 5) {
const y = u.toString(10);
}

if (u === true || u === false) {
if (u === true || u === false) {
const someBool: boolean = u;
}

Expand All @@ -25,28 +25,93 @@ if (u === null) {
const someNull: null = u;
}

if(u === symb) {
if (u === symb) {
const symbolAlias: typeof symb = u;
}

if (!(u === 42)) {
u // u should still be `unknown` here
type A = isTrue<isUnknown<typeof u>>
}

if (u !== 42) {
type A = isTrue<isUnknown<typeof u>>
type B = isTrue<isUnknown<typeof u>>
}

if (u == 42) {
type B = isTrue<isUnknown<typeof u>>
type C = isTrue<isUnknown<typeof u>>
}

if (u == true) {
type C = isTrue<isUnknown<typeof u>>
type D = isTrue<isUnknown<typeof u>>
}

if (u == Object) {
type D = isTrue<isUnknown<typeof u>>
type E = isTrue<isUnknown<typeof u>>
}

declare const aString: string;
declare const aBoolean: boolean;
declare const aNumber: number;
declare const anObject: object;
declare const anObjectLiteral: { x: number };
declare const aUnion: { x: number } | { y: string };
declare const anIntersection: { x: number } & { y: string };
declare const aFunction: () => number;

if (u === aString) {
let uString: string = u;
}

if (u === aBoolean) {
let uString: boolean = u;
}

if (u === aNumber) {
let uNumber: number = u;
}

if (u === anObject) {
let uObject: object = u;
}

if (u === anObjectLiteral) {
let uObjectLiteral: object = u;
}

if (u === aUnion) {
type unionDoesNotNarrow = isTrue<isUnknown<typeof u>>
}

if (u === anIntersection) {
type intersectionDoesNotNarrow = isTrue<isUnknown<typeof u>>
}

if (u === aFunction) {
let uFunction: object = u;
}

enum NumberEnum {
A,
B,
C
}

enum StringEnum {
A = "A",
B = "B",
C = "C"
}

if (u === NumberEnum || u === StringEnum) {
let enumObj: object = u;
}

if(u === NumberEnum.A) {
let a: NumberEnum.A = u
}

if(u === StringEnum.B) {
let b: StringEnum.B = u
}


Expand All @@ -70,7 +135,6 @@ if (u === symb) {
var symbolAlias = u;
}
if (!(u === 42)) {
u; // u should still be `unknown` here
}
if (u !== 42) {
}
Expand All @@ -80,3 +144,46 @@ if (u == true) {
}
if (u == Object) {
}
if (u === aString) {
var uString = u;
}
if (u === aBoolean) {
var uString = u;
}
if (u === aNumber) {
var uNumber = u;
}
if (u === anObject) {
var uObject = u;
}
if (u === anObjectLiteral) {
var uObjectLiteral = u;
}
if (u === aUnion) {
}
if (u === anIntersection) {
}
if (u === aFunction) {
var uFunction = u;
}
var NumberEnum;
(function (NumberEnum) {
NumberEnum[NumberEnum["A"] = 0] = "A";
NumberEnum[NumberEnum["B"] = 1] = "B";
NumberEnum[NumberEnum["C"] = 2] = "C";
})(NumberEnum || (NumberEnum = {}));
var StringEnum;
(function (StringEnum) {
StringEnum["A"] = "A";
StringEnum["B"] = "B";
StringEnum["C"] = "C";
})(StringEnum || (StringEnum = {}));
if (u === NumberEnum || u === StringEnum) {
var enumObj = u;
}
if (u === NumberEnum.A) {
var a = u;
}
if (u === StringEnum.B) {
var b = u;
}
Loading

0 comments on commit a8cc939

Please sign in to comment.