Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
07a696f
Rename existing unknownType to errorType
ahejlsberg May 26, 2018
8f193b4
Free up one bit in TypeFlags
ahejlsberg May 26, 2018
8b2149e
Accept new baselines
ahejlsberg May 26, 2018
03f464f
Add 'unknown' keyword to scanner/parser/emitter
ahejlsberg May 26, 2018
d225065
Accept new baselines
ahejlsberg May 26, 2018
2003b2a
Implement 'unknown' type in checker
ahejlsberg May 26, 2018
5a0910a
Accept new baselines
ahejlsberg May 26, 2018
b20925a
'null' and 'undefined' are bottom types in non-strictNullChecks mode
ahejlsberg May 26, 2018
9e4d19f
Fixes to keyof and narrowing by typeof check
ahejlsberg May 27, 2018
f63b61c
Accept new baselines
ahejlsberg May 27, 2018
79e7700
{ [P in unknown]: XXX } should resolve to { [x: string]: XXX }
ahejlsberg May 27, 2018
73af0ad
Add tests
ahejlsberg May 27, 2018
5da063f
Accept new baselines
ahejlsberg May 27, 2018
353802c
Check we have non-unknown where we require non-nullable
ahejlsberg May 27, 2018
a83653e
Add new diagnostic
ahejlsberg May 27, 2018
31c73de
Update tests
ahejlsberg May 27, 2018
a4a73df
Accept new baselines
ahejlsberg May 27, 2018
074961f
keyof unknown should be never
ahejlsberg May 29, 2018
c694ffe
Update tests
ahejlsberg May 29, 2018
e98f9a6
Accept new baselines
ahejlsberg May 29, 2018
6b1c84e
Remove eager resolution of distributive conditional types
ahejlsberg May 30, 2018
577662d
Update tests
ahejlsberg May 30, 2018
41ef7a7
Accept new baselines
ahejlsberg May 30, 2018
e22a9d6
Merge branch 'master' into unknownType
ahejlsberg May 30, 2018
8664390
Rename unknownType to errorType in merged code
ahejlsberg May 30, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Accept new baselines
  • Loading branch information
ahejlsberg committed May 27, 2018
commit a4a73df839cc6c7ed5f68aad69002ee5c03ab5e3
12 changes: 6 additions & 6 deletions tests/baselines/reference/mappedTypes4.types
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ function boxify<T>(obj: T): Boxified<T> {

for (let k in obj) {
>k : Extract<keyof T, string>
>obj : T & object
>obj : T

result[k] = { value: obj[k] };
>result[k] = { value: obj[k] } : { value: (T & object)[Extract<keyof T, string>]; }
>result[k] = { value: obj[k] } : { value: T[Extract<keyof T, string>]; }
>result[k] : Boxified<T>[Extract<keyof T, string>]
>result : Boxified<T>
>k : Extract<keyof T, string>
>{ value: obj[k] } : { value: (T & object)[Extract<keyof T, string>]; }
>value : (T & object)[Extract<keyof T, string>]
>obj[k] : (T & object)[Extract<keyof T, string>]
>obj : T & object
>{ value: obj[k] } : { value: T[Extract<keyof T, string>]; }
>value : T[Extract<keyof T, string>]
>obj[k] : T[Extract<keyof T, string>]
>obj : T
>k : Extract<keyof T, string>
}
return result;
Expand Down
109 changes: 86 additions & 23 deletions tests/baselines/reference/unknownType1.errors.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
tests/cases/conformance/types/unknown/unknownType1.ts(87,9): error TS2322: Type 'unknown' is not assignable to type 'object'.
tests/cases/conformance/types/unknown/unknownType1.ts(88,9): error TS2322: Type 'unknown' is not assignable to type 'string'.
tests/cases/conformance/types/unknown/unknownType1.ts(89,9): error TS2322: Type 'unknown' is not assignable to type 'string[]'.
tests/cases/conformance/types/unknown/unknownType1.ts(90,9): error TS2322: Type 'unknown' is not assignable to type '{}'.
tests/cases/conformance/types/unknown/unknownType1.ts(91,9): error TS2322: Type 'unknown' is not assignable to type '{} | null | undefined'.
tests/cases/conformance/types/unknown/unknownType1.ts(45,5): error TS2571: Object is of type 'unknown'.
tests/cases/conformance/types/unknown/unknownType1.ts(46,5): error TS2571: Object is of type 'unknown'.
tests/cases/conformance/types/unknown/unknownType1.ts(47,5): error TS2571: Object is of type 'unknown'.
tests/cases/conformance/types/unknown/unknownType1.ts(48,5): error TS2571: Object is of type 'unknown'.
tests/cases/conformance/types/unknown/unknownType1.ts(49,5): error TS2571: Object is of type 'unknown'.
tests/cases/conformance/types/unknown/unknownType1.ts(50,5): error TS2571: Object is of type 'unknown'.
tests/cases/conformance/types/unknown/unknownType1.ts(51,6): error TS2571: Object is of type 'unknown'.
tests/cases/conformance/types/unknown/unknownType1.ts(52,6): error TS2571: Object is of type 'unknown'.
tests/cases/conformance/types/unknown/unknownType1.ts(58,5): error TS2571: Object is of type 'unknown'.
tests/cases/conformance/types/unknown/unknownType1.ts(59,5): error TS2571: Object is of type 'unknown'.
tests/cases/conformance/types/unknown/unknownType1.ts(60,5): error TS2571: Object is of type 'unknown'.
tests/cases/conformance/types/unknown/unknownType1.ts(61,9): error TS2571: Object is of type 'unknown'.
tests/cases/conformance/types/unknown/unknownType1.ts(105,9): error TS2322: Type 'unknown' is not assignable to type 'object'.
tests/cases/conformance/types/unknown/unknownType1.ts(106,9): error TS2322: Type 'unknown' is not assignable to type 'string'.
tests/cases/conformance/types/unknown/unknownType1.ts(107,9): error TS2322: Type 'unknown' is not assignable to type 'string[]'.
tests/cases/conformance/types/unknown/unknownType1.ts(108,9): error TS2322: Type 'unknown' is not assignable to type '{}'.
tests/cases/conformance/types/unknown/unknownType1.ts(109,9): error TS2322: Type 'unknown' is not assignable to type '{} | null | undefined'.
Type 'unknown' is not assignable to type '{}'.
tests/cases/conformance/types/unknown/unknownType1.ts(97,9): error TS2322: Type 'T' is not assignable to type 'object'.
tests/cases/conformance/types/unknown/unknownType1.ts(106,5): error TS2322: Type '123' is not assignable to type '{ [x: string]: unknown; }'.
tests/cases/conformance/types/unknown/unknownType1.ts(132,5): error TS2564: Property 'a' has no initializer and is not definitely assigned in the constructor.
tests/cases/conformance/types/unknown/unknownType1.ts(115,9): error TS2322: Type 'T' is not assignable to type 'object'.
tests/cases/conformance/types/unknown/unknownType1.ts(124,5): error TS2322: Type '123' is not assignable to type '{ [x: string]: unknown; }'.
tests/cases/conformance/types/unknown/unknownType1.ts(150,14): error TS2700: Rest types may only be created from object types.
tests/cases/conformance/types/unknown/unknownType1.ts(156,5): error TS2564: Property 'a' has no initializer and is not definitely assigned in the constructor.


==== tests/cases/conformance/types/unknown/unknownType1.ts (8 errors) ====
==== tests/cases/conformance/types/unknown/unknownType1.ts (21 errors) ====
// In an intersection everything absorbs unknown

type T00 = unknown & null; // null
Expand Down Expand Up @@ -49,20 +62,62 @@ tests/cases/conformance/types/unknown/unknownType1.ts(132,5): error TS2564: Prop
type T40 = keyof any; // string | number | symbol
type T41 = keyof unknown; // string | number | symbol

// Only equality operators are allowed with unknown

function f10(x: unknown) {
x == 5;
x !== 10;
x >= 0; // Error
~
!!! error TS2571: Object is of type 'unknown'.
x.foo; // Error
~
!!! error TS2571: Object is of type 'unknown'.
x[10]; // Error
~
!!! error TS2571: Object is of type 'unknown'.
x(); // Error
~
!!! error TS2571: Object is of type 'unknown'.
x + 1; // Error
~
!!! error TS2571: Object is of type 'unknown'.
x * 2; // Error
~
!!! error TS2571: Object is of type 'unknown'.
-x; // Error
~
!!! error TS2571: Object is of type 'unknown'.
+x; // Error
~
!!! error TS2571: Object is of type 'unknown'.
}

// No property accesses, element accesses, or function calls

function f11(x: unknown) {
x.foo; // Error
~
!!! error TS2571: Object is of type 'unknown'.
x[5]; // Error
~
!!! error TS2571: Object is of type 'unknown'.
x(); // Error
~
!!! error TS2571: Object is of type 'unknown'.
new x(); // Error
~
!!! error TS2571: Object is of type 'unknown'.
}

// typeof, instanceof, and user defined type predicates

declare function isFunction(x: unknown): x is Function;

function f1(x: unknown) {
function f20(x: unknown) {
if (typeof x === "string" || typeof x === "number") {
x; // string | number
}
if (typeof x === "object") {
x; // object
}
if (typeof x === "function") {
x; // object
}
if (x instanceof Error) {
x; // Error
}
Expand All @@ -79,7 +134,7 @@ tests/cases/conformance/types/unknown/unknownType1.ts(132,5): error TS2564: Prop

// Anything is assignable to unknown

function f2<T>(pAny: any, pNever: never, pT: T) {
function f21<T>(pAny: any, pNever: never, pT: T) {
let x: unknown;
x = 123;
x = "hello";
Expand All @@ -93,7 +148,7 @@ tests/cases/conformance/types/unknown/unknownType1.ts(132,5): error TS2564: Prop

// unknown assignable only to itself and any

function f3(x: unknown) {
function f22(x: unknown) {
let v1: any = x;
let v2: unknown = x;
let v3: object = x; // Error
Expand All @@ -116,15 +171,15 @@ tests/cases/conformance/types/unknown/unknownType1.ts(132,5): error TS2564: Prop

// Type parameter 'T extends unknown' not related to object

function f4<T extends unknown>(x: T) {
function f23<T extends unknown>(x: T) {
let y: object = x; // Error
~
!!! error TS2322: Type 'T' is not assignable to type 'object'.
}

// Anything but primitive assignable to { [x: string]: unknown }

function f5(x: { [x: string]: unknown }) {
function f24(x: { [x: string]: unknown }) {
x = {};
x = { a: 5 };
x = [1, 2, 3];
Expand All @@ -135,22 +190,30 @@ tests/cases/conformance/types/unknown/unknownType1.ts(132,5): error TS2564: Prop

// Locals of type unknown always considered initialized

function f6() {
function f25() {
let x: unknown;
let y = x;
}

// Spread of unknown causes result to be unknown

function f7(x: {}, y: unknown, z: any) {
function f26(x: {}, y: unknown, z: any) {
let o1 = { a: 42, ...x }; // { a: number }
let o2 = { a: 42, ...x, ...y }; // unknown
let o3 = { a: 42, ...x, ...y, ...z }; // any
}

// Functions with unknown return type don't need return expressions

function f8(): unknown {
function f27(): unknown {
}

// Rest type cannot be created from unknown

function f28(x: unknown) {
let { ...a } = x; // Error
~
!!! error TS2700: Rest types may only be created from object types.
}

// Class properties of type unknown don't need definite assignment
Expand Down
Loading