8000 Improved type inference for object literals by ahejlsberg · Pull Request #19513 · microsoft/TypeScript · GitHub
[go: up one dir, main page]

Skip to content

Improved type inference for object literals #19513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Oct 29, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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 Oct 28, 2017
commit 709541cfe968e6f46e32f0c75a0809da19a33a5d
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var r = true ? 1 : 2;
>2 : 2

var r3 = true ? 1 : {};
>r3 : {}
>r3 : number | {}
>true ? 1 : {} : 1 | {}
>true : true
>1 : 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ true ? { a: 1 } : { a: 2, b: 'string' };
>'string' : "string"

var result2 = true ? {} : 1;
>result2 : {}
>result2 : number | {}
>true ? {} : 1 : 1 | {}
>true : true
>{} : {}
Expand Down Expand Up @@ -143,7 +143,7 @@ true ? { a: 2, b: 'string' } : { a: 1 };
>1 : 1

var result6 = true ? 1 : {};
>result6 : {}
>result6 : number | {}
>true ? 1 : {} : 1 | {}
>true : true
>1 : 1
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/heterogeneousArrayLiterals.types
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ var c = [1, '', null]; // {}[]
>null : null

var d = [{}, 1]; // {}[]
>d : {}[]
>d : (number | {})[]
>[{}, 1] : (number | {})[]
>{} : {}
>1 : 1

var e = [{}, Object]; // {}[]
>e : {}[]
>e : (ObjectConstructor | {})[]
>[{}, Object] : (ObjectConstructor | {})[]
>{} : {}
>Object : ObjectConstructor
Expand Down
6 changes: 3 additions & 3 deletions tests/baselines/reference/objectSpread.types
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ function conditionalSpreadBoolean(b: boolean) : { x: number, y: number } {
>14 : 14
}
let o2 = { ...b && { x: 21 }}
>o2 : {}
>o2 : {} | { x: number; }
>{ ...b && { x: 21 }} : {} | { x: number; }
>b && { x: 21 } : false | { x: number; }
>b : boolean
Expand Down Expand Up @@ -336,7 +336,7 @@ function conditionalSpreadNumber(nt: number): { x: number, y: number } {
>nt : number
}
let o2 = { ...nt && { x: nt }}
>o2 : {}
>o2 : {} | { x: number; }
>{ ...nt && { x: nt }} : {} | { x: number; }
>nt && { x: nt } : 0 | { x: number; }
>nt : number
Expand Down Expand Up @@ -377,7 +377,7 @@ function conditionalSpreadString(st: string): { x: string, y: number } {
>st : string
}
let o2 = { ...st && { x: st }}
>o2 : {}
>o2 : {} | { x: string; }
>{ ...st && { x: st }} : {} | { x: string; }
>st && { x: st } : "" | { x: string; }
>st : string
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/primitiveMembers.types
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ var b: Boolean = true;
>true : true

var n3 = 5 || {};
>n3 : {}
>n3 : number | {}
>5 || {} : 5 | {}
>5 : 5
>{} : {}
Expand Down
41 changes: 0 additions & 41 deletions tests/baselines/reference/spreadUnion2.errors.txt

This file was deleted.

6 changes: 4 additions & 2 deletions tests/baselines/reference/spreadUnion3.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ tests/cases/conformance/types/spread/spreadUnion3.ts(2,5): error TS2322: Type '{
Type '{ y: number; }' is not assignable to type '{ y: string; }'.
Types of property 'y' are incompatible.
Type 'number' is not assignable to type 'string'.
tests/cases/conformance/types/spread/spreadUnion3.ts(9,23): error TS2339: Property 'a' does not exist on type '{}'.
tests/cases/conformance/types/spread/spreadUnion3.ts(9,23): error TS2339: Property 'a' does not exist on type '{} | {} | { a: number; }'.
Property 'a' does not exist on type '{}'.
tests/cases/conformance/types/spread/spreadUnion3.ts(17,11): error TS2698: Spread types may only be created from object types.
tests/cases/conformance/types/spread/spreadUnion3.ts(18,11): error TS2698: Spread types may only be created from object types.

Expand All @@ -23,7 +24,8 @@ tests/cases/conformance/types/spread/spreadUnion3.ts(18,11): error TS2698: Sprea
let b = { ...t };
let c: number = b.a; // might not have 'a'
~
!!! error TS2339: Property 'a' does not exist on type '{}'.
!!! error TS2339: Property 'a' does not exist on type '{} | {} | { a: number; }'.
!!! error TS2339: Property 'a' does not exist on type '{}'.
}
g()
g(undefined)
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/spreadUnion3.types
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ function g(t?: { a: number } | null): void {
>null : null

let b = { ...t };
>b : {}
>b : {} | {} | { a: number; }
>{ ...t } : {} | {} | { a: number; }
>t : { a: number; } | null | undefined

let c: number = b.a; // might not have 'a'
>c : number
>b.a : any
>b : {}
>b : {} | {} | { a: number; }
>a : any
}
g()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -675,14 +675,14 @@ function f21<T extends Number>(x: T) {
>T : T

var r20 = true ? {} : x; // ok
>r20 : {}
>r20 : T | {}
>true ? {} : x : T | {}
>true : true
>{} : {}
>x : T

var r20 = true ? x : {}; // ok
>r20 : {}
>r20 : T | {}
>true ? x : {} : T | {}
>true : true
>x : T
Expand Down
0