You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improve intersection reduction and CFA for truthy, equality, and typeof checks (microsoft#49119)
* Improve reduction of intersection types
* Accept new baselines
* Improve CFA for truthy, equality, and typeof checks
* Accept new baselines
* Remove special case for Function type
* Don't reduce intersections of form {...} & object
* Accept new baselines
* Anything is assignable to unknown-like union
* Accept new baselines
* Tweak subtype check
* Recombine unknown type from unknown-like union in more cases
* Display union origin only if it is shorter than union itself
* Accept new baselines
* Add tests
* Only attach origin type when it is shorter than union itself
* Specially preserve string & {}, number & {}, bigint & {}
* Accept new baselines
* Add additional tests
* Fix getNormalizedType and getNarrowableTypeForReference for intersections
* Switch NonNullable<T> to use T & {}
* Accept new baselines
* Use NonNullable<T> in place of anonymous T & {}
* Accept new baselines
* Add fourslash test
* More fourslash tests
* Fix getFalsyFlags handling of intersections
* Accept new baselines
* Add constraint to compareProperties type parameter
* Unconstrained type parameter not assignable to {} with strictNullChecks
* Accept new baselines
Copy file name to clipboardExpand all lines: src/compiler/diagnosticMessages.json
+4Lines changed: 4 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1526,6 +1526,10 @@
1526
1526
"category": "Error",
1527
1527
"code": 2207
1528
1528
},
1529
+
"This type parameter probably needs an `extends object` constraint.": {
1530
+
"category": "Error",
1531
+
"code": 2208
1532
+
},
1529
1533
1530
1534
"The project root is ambiguous, but is required to resolve export map entry '{0}' in file '{1}'. Supply the `rootDir` compiler option to disambiguate.": {
Copy file name to clipboardExpand all lines: tests/baselines/reference/conditionalTypes1.errors.txt
+25-2Lines changed: 25 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,23 @@
1
1
tests/cases/conformance/types/conditional/conditionalTypes1.ts(12,5): error TS2322: Type 'T' is not assignable to type 'NonNullable<T>'.
2
+
Type 'T' is not assignable to type '{}'.
2
3
tests/cases/conformance/types/conditional/conditionalTypes1.ts(17,5): error TS2322: Type 'T' is not assignable to type 'NonNullable<T>'.
3
4
Type 'string | undefined' is not assignable to type 'NonNullable<T>'.
4
5
Type 'undefined' is not assignable to type 'NonNullable<T>'.
6
+
Type 'undefined' is not assignable to type 'T'.
7
+
'undefined' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string | undefined'.
8
+
Type 'T' is not assignable to type '{}'.
9
+
Type 'string | undefined' is not assignable to type '{}'.
10
+
Type 'undefined' is not assignable to type '{}'.
5
11
tests/cases/conformance/types/conditional/conditionalTypes1.ts(24,5): error TS2322: Type 'T[keyof T] | undefined' is not assignable to type 'NonNullable<Partial<T>[keyof T]>'.
6
-
Type 'undefined' is not assignable to type 'NonNullable<Partial<T>[keyof T]>'.
12
+
Type 'undefined' is not assignable to type 'T[keyof T] & {}'.
13
+
Type 'undefined' is not assignable to type 'T[keyof T]'.
7
14
tests/cases/conformance/types/conditional/conditionalTypes1.ts(29,5): error TS2322: Type 'T["x"]' is not assignable to type 'NonNullable<T["x"]>'.
8
15
Type 'string | undefined' is not assignable to type 'NonNullable<T["x"]>'.
9
16
Type 'undefined' is not assignable to type 'NonNullable<T["x"]>'.
17
+
Type 'undefined' is not assignable to type '{}'.
18
+
Type 'T["x"]' is not assignable to type '{}'.
19
+
Type 'string | undefined' is not assignable to type '{}'.
20
+
Type 'undefined' is not assignable to type '{}'.
10
21
tests/cases/conformance/types/conditional/conditionalTypes1.ts(103,5): error TS2322: Type 'FunctionProperties<T>' is not assignable to type 'T'.
11
22
'T' could be instantiated with an arbitrary type which could be unrelated to 'FunctionProperties<T>'.
12
23
tests/cases/conformance/types/conditional/conditionalTypes1.ts(104,5): error TS2322: Type 'NonFunctionProperties<T>' is not assignable to type 'T'.
!!! error TS2322: Type 'T' is not assignable to type 'NonNullable<T>'.
86
+
!!! error TS2322: Type 'T' is not assignable to type '{}'.
87
+
!!! related TS2208 tests/cases/conformance/types/conditional/conditionalTypes1.ts:10:13: This type parameter probably needs an `extends object` constraint.
75
88
}
76
89
77
90
function f2<T extends string | undefined>(x: T, y: NonNullable<T>) {
!!! error TS2322: Type 'T' is not assignable to type 'NonNullable<T>'.
82
95
!!! error TS2322: Type 'string | undefined' is not assignable to type 'NonNullable<T>'.
83
96
!!! error TS2322: Type 'undefined' is not assignable to type 'NonNullable<T>'.
97
+
!!! error TS2322: Type 'undefined' is not assignable to type 'T'.
98
+
!!! error TS2322: 'undefined' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string | undefined'.
99
+
!!! error TS2322: Type 'T' is not assignable to type '{}'.
100
+
!!! error TS2322: Type 'string | undefined' is not assignable to type '{}'.
101
+
!!! error TS2322: Type 'undefined' is not assignable to type '{}'.
Property 'bat' is missing in type 'Foo & Bar' but required in type '{ foo: string; bat: string; }'.
33
33
tests/cases/conformance/types/conditional/conditionalTypes2.ts(75,12): error TS2345: Argument of type 'Extract2<T, Foo, Bar>' is not assignable to parameter of type '{ foo: string; bat: string; }'.
34
34
Type 'T extends Bar ? T : never' is not assignable to type '{ foo: string; bat: string; }'.
35
-
Property 'bat' is missing in type 'Bar & Foo' but required in type '{ foo: string; bat: string; }'.
35
+
Type 'Bar & Foo & T' is not assignable to type '{ foo: string; bat: string; }'.
0 commit comments