Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ce23b8d
Improve reduction of intersection types
ahejlsberg May 5, 2022
ffe147e
Accept new baselines
ahejlsberg May 5, 2022
a95de48
Merge branch 'main' into improveIntersectionReduction
ahejlsberg May 13, 2022
29edef1
Improve CFA for truthy, equality, and typeof checks
ahejlsberg May 15, 2022
39326d7
Accept new baselines
ahejlsberg May 15, 2022
d0b7ec8
Remove special case for Function type
ahejlsberg May 15, 2022
a25388d
Merge branch 'main' into improveIntersectionReduction
ahejlsberg May 15, 2022
95c3c56
Don't reduce intersections of form {...} & object
ahejlsberg May 15, 2022
986963c
Accept new baselines
ahejlsberg May 15, 2022
c400181
Anything is assignable to unknown-like union
ahejlsberg May 16, 2022
f1ebcdd
Accept new baselines
ahejlsberg May 16, 2022
73c91fd
Tweak subtype check
ahejlsberg May 16, 2022
722c462
Recombine unknown type from unknown-like union in more cases
ahejlsberg May 17, 2022
5e1111a
Display union origin only if it is shorter than union itself
ahejlsberg May 18, 2022
5c579a4
Accept new baselines
ahejlsberg May 18, 2022
8913cf0
Add tests
ahejlsberg May 18, 2022
dbce210
Only attach origin type when it is shorter than union itself
ahejlsberg May 19, 2022
1913c94
Specially preserve string & {}, number & {}, bigint & {}
ahejlsberg May 20, 2022
8c7a38b
Accept new baselines
ahejlsberg May 20, 2022
6f18e90
Add additional tests
ahejlsberg May 20, 2022
e70bf7c
Fix getNormalizedType and getNarrowableTypeForReference for intersect…
ahejlsberg May 20, 2022
7a62983
Switch NonNullable<T> to use T & {}
ahejlsberg May 20, 2022
c35cba7
Accept new baselines
ahejlsberg May 20, 2022
a0c0929
Use NonNullable<T> in place of anonymous T & {}
ahejlsberg May 20, 2022
eff3be3
Accept new baselines
ahejlsberg May 20, 2022
d3eb84f
Add fourslash test
ahejlsberg May 24, 2022
954e80a
More fourslash tests
ahejlsberg May 24, 2022
1d9b53f
Fix getFalsyFlags handling of intersections
ahejlsberg May 26, 2022
3815934
Accept new baselines
ahejlsberg May 26, 2022
bfa3a90
Add constraint to compareProperties type parameter
ahejlsberg May 26, 2022
9801667
Unconstrained type parameter not assignable to {} with strictNullChecks
ahejlsberg May 26, 2022
51da289
Accept new baselines
ahejlsberg May 26, 2022
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 15, 2022
commit 986963cde0223e4e4d48fb3afce704a1e6ef7906
12 changes: 6 additions & 6 deletions tests/baselines/reference/intersectionOfUnionNarrowing.types
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,25 @@ declare const q: X & AorB;

if (q.a !== undefined) {
>q.a !== undefined : boolean
>q.a : { aProp: string; } | undefined
>q.a : ({ aProp: string; } & object) | undefined
>q : X & AorB
>a : { aProp: string; } | undefined
>a : ({ aProp: string; } & object) | undefined
>undefined : undefined

q.a.aProp;
>q.a.aProp : string
>q.a : { aProp: string; }
>q.a : { aProp: string; } & object
>q : X & { a: object; b: undefined; }
>a : { aProp: string; }
>a : { aProp: string; } & object
>aProp : string

} else {
// q.b is previously incorrectly inferred as potentially undefined
q.b.bProp;
>q.b.bProp : string
>q.b : { bProp: string; }
>q.b : { bProp: string; } & object
>q : X & { a: undefined; b: object; }
>b : { bProp: string; }
>b : { bProp: string; } & object
>bProp : string
}

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
tests/cases/conformance/types/nonPrimitive/nonPrimitiveUnionIntersection.ts(1,5): error TS2322: Type 'string' is not assignable to type 'never'.
tests/cases/conformance/types/nonPrimitive/nonPrimitiveUnionIntersection.ts(3,5): error TS2322: Type 'number' is not assignable to type 'object'.
tests/cases/conformance/types/nonPrimitive/nonPrimitiveUnionIntersection.ts(4,1): error TS2322: Type 'string' is not assignable to type 'never'.
tests/cases/conformance/types/nonPrimitive/nonPrimitiveUnionIntersection.ts(8,38): error TS2322: Type '{ bar: string; }' is not assignable to type '{ err: string; }'.
Object literal may only specify known properties, and 'bar' does not exist in type '{ err: string; }'.
tests/cases/conformance/types/nonPrimitive/nonPrimitiveUnionIntersection.ts(8,38): error TS2322: Type '{ bar: string; }' is not assignable to type 'object & { err: string; }'.
Object literal may only specify known properties, and 'bar' does not exist in type 'object & { err: string; }'.


==== tests/cases/conformance/types/nonPrimitive/nonPrimitiveUnionIntersection.ts (4 errors) ====
Expand All @@ -21,6 +21,6 @@ tests/cases/conformance/types/nonPrimitive/nonPrimitiveUnionIntersection.ts(8,38
const foo: object & {} = {bar: 'bar'}; // ok
const bar: object & {err: string} = {bar: 'bar'}; // error
~~~~~~~~~~
!!! error TS2322: Type '{ bar: string; }' is not assignable to type '{ err: string; }'.
!!! error TS2322: Object literal may only specify known properties, and 'bar' does not exist in type '{ err: string; }'.
!!! error TS2322: Type '{ bar: string; }' is not assignable to type 'object & { err: string; }'.
!!! error TS2322: Object literal may only specify known properties, and 'bar' does not exist in type 'object & { err: string; }'.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const foo: object & {} = {bar: 'bar'}; // ok
>'bar' : "bar"

const bar: object & {err: string} = {bar: 'bar'}; // error
>bar : { err: string; }
>bar : object & { err: string; }
>err : string
>{bar: 'bar'} : { bar: string; }
>bar : string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ tests/cases/compiler/objectLiteralExcessProperties.ts(43,43): error TS2322: Type
Object literal may only specify known properties, and 'name' does not exist in type '{ prop: boolean; }'.
tests/cases/compiler/objectLiteralExcessProperties.ts(45,76): error TS2322: Type '{ name: string; prop: boolean; }' is not assignable to type '(T & { prop: boolean; }) | { name: string; }'.
Object literal may only specify known properties, and 'prop' does not exist in type '{ name: string; }'.
tests/cases/compiler/objectLiteralExcessProperties.ts(49,44): error TS2322: Type '{ z: string; }' is not assignable to type '{ x: string; }'.
Object literal may only specify known properties, and 'z' does not exist in type '{ x: string; }'.
tests/cases/compiler/objectLiteralExcessProperties.ts(49,44): error TS2322: Type '{ z: string; }' is not assignable to type 'object & { x: string; }'.
Object literal may only specify known properties, and 'z' does not exist in type 'object & { x: string; }'.


==== tests/cases/compiler/objectLiteralExcessProperties.ts (16 errors) ====
Expand Down Expand Up @@ -129,7 +129,7 @@ tests/cases/compiler/objectLiteralExcessProperties.ts(49,44): error TS2322: Type
// The 'object' type has no effect on intersections
const obj6: object & { x: string } = { z: 'abc' }
~~~~~~~~
!!! error TS2322: Type '{ z: string; }' is not assignable to type '{ x: string; }'.
!!! error TS2322: Object literal may only specify known properties, and 'z' does not exist in type '{ x: string; }'.
!!! error TS2322: Type '{ z: string; }' is not assignable to type 'object & { x: string; }'.
!!! error TS2322: Object literal may only specify known properties, and 'z' does not exist in type 'object & { x: string; }'.
}

Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function test<T extends IFoo>() {

// The 'object' type has no effect on intersections
const obj6: object & { x: string } = { z: 'abc' }
>obj6 : { x: string; }
>obj6 : object & { x: string; }
>x : string
>{ z: 'abc' } : { z: string; }
>z : string
Expand Down
6 changes: 3 additions & 3 deletions tests/baselines/reference/recursiveTypeRelations.types
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type ClassNameMap<S> = { [K in keyof S]?: boolean }
>ClassNameMap : ClassNameMap<S>

type ClassNameObjectMap<S> = object & ClassNameMap<S>;
>ClassNameObjectMap : ClassNameMap<S>
>ClassNameObjectMap : ClassNameObjectMap<S>

type ClassNameArg<S> = ClassName<S> | ClassNameObjectMap<S>;
>ClassNameArg : ClassNameArg<S>
Expand Down Expand Up @@ -75,7 +75,7 @@ export function css<S extends { [K in keyof S]: string }>(styles: S, ...classNam
>Object.keys : (o: object) => string[]
>Object : ObjectConstructor
>keys : (o: object) => string[]
>arg : ClassNameMap<S>
>arg : ClassNameObjectMap<S>
>reduce : { (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string): string; (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string, initialValue: string): string; <U>(callbackfn: (previousValue: U, currentValue: string, currentIndex: number, array: string[]) => U, initialValue: U): U; }
>(obj: ClassNameObject, key: keyof S) => { const exportedClassName = styles[key]; obj[exportedClassName] = (arg as ClassNameMap<S>)[key]; return obj; } : (obj: ClassNameObject, key: keyof S) => ClassNameObject
>obj : ClassNameObject
Expand All @@ -95,7 +95,7 @@ export function css<S extends { [K in keyof S]: string }>(styles: S, ...classNam
>(arg as ClassNameMap<S>)[key] : boolean
>(arg as ClassNameMap<S>) : ClassNameMap<S>
>arg as ClassNameMap<S> : ClassNameMap<S>
>arg : ClassNameMap<S>
>arg : ClassNameObjectMap<S>
>key : keyof S

return obj;
Expand Down