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
8f2e00f
Create separate types for equivalent aliased unions
ahejlsberg Dec 25, 2020
1e9ea77
Accept new baselines
ahejlsberg Dec 25, 2020
c9bea0c
Preserve original types for union types
ahejlsberg Dec 28, 2020
2e2048c
Accept new baselines
ahejlsberg Dec 28, 2020
44231c8
Preserve intersection origin for union types
ahejlsberg Dec 29, 2020
829285f
Accept new baselines
ahejlsberg Dec 29, 2020
536e41e
Accept new baselines
ahejlsberg Dec 29, 2020
cc5d0f2
Preserve aliases during relationship checks
ahejlsberg Dec 29, 2020
b2434fc
Accept new baselines
ahejlsberg Dec 29, 2020
6c1248e
Preserve aliases for intersection and indexed access types
ahejlsberg Dec 29, 2020
237e9ca
Accept new baselines
ahejlsberg Dec 29, 2020
d4dc215
Compute intersection-of-unions cross product without recursion
ahejlsberg Dec 30, 2020
11d2712
Accept new baselines
ahejlsberg Dec 30, 2020
39f82a8
Use denormalized type objects for origin / support 'keyof' origins
ahejlsberg Jan 1, 2021
d9a0f50
Accept new baselines
ahejlsberg Jan 1, 2021
e0d4774
Fix fourslash test
ahejlsberg Jan 1, 2021
21f61c0
Recursively extract named union types
ahejlsberg Jan 2, 2021
785d2b7
Accept new baselines
ahejlsberg Jan 2, 2021
d98caab
Map on union origin in mapType to better preserve aliases and origins
ahejlsberg Jan 3, 2021
260a665
Remove redundant call
ahejlsberg Jan 4, 2021
8597325
Accept new baselines
ahejlsberg Jan 4, 2021
5f7e126
Revert back to declared type when branches produce equivalent union
ahejlsberg Jan 4, 2021
8ef90e7
Accept new baselines
ahejlsberg Jan 4, 2021
4c9675c
Merge branch 'master' into preserveTypeAliases
ahejlsberg Jan 4, 2021
3fce1b9
Don't include denormal origin types in regular type statistics
ahejlsberg Jan 4, 2021
99355c5
Merge branch 'master' into preserveTypeAliases
ahejlsberg Jan 5, 2021
e388a26
Fix issue with unions not being marked primitive-only
ahejlsberg Jan 5, 2021
2c2d06d
Allow new alias to be associated with type alias instantiation
ahejlsberg Jan 8, 2021
4507270
Accept new baselines
ahejlsberg Jan 8, 2021
e794cb9
Merge branch 'master' into preserveTypeAliases
ahejlsberg Jan 8, 2021
4e123f5
Revert "Accept new baselines"
ahejlsberg Jan 9, 2021
8881f01
Revert "Allow new alias to be associated with type alias instantiation"
ahejlsberg Jan 9, 2021
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 Dec 28, 2020
commit 2e2048caccb8ab66d5d31bdc0d696989fd103cc6
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ animal.canMeow; // since is cat, should not be an error
>canMeow : true

const animalOrUndef = { type: 'cat', canMeow: true } as Animal | undefined;
>animalOrUndef : Cat | Dog | undefined
>{ type: 'cat', canMeow: true } as Animal | undefined : Cat | Dog | undefined
>animalOrUndef : Animal | undefined
>{ type: 'cat', canMeow: true } as Animal | undefined : Animal | undefined
>{ type: 'cat', canMeow: true } : { type: "cat"; canMeow: true; }
>type : "cat"
>'cat' : "cat"
Expand All @@ -61,7 +61,7 @@ assertEqual(animalOrUndef?.type, 'cat' as const);
>assertEqual(animalOrUndef?.type, 'cat' as const) : void
>assertEqual : <T>(value: any, type: T) => asserts value is T
>animalOrUndef?.type : "cat" | "dog" | undefined
>animalOrUndef : Cat | Dog | undefined
>animalOrUndef : Animal | undefined
>type : "cat" | "dog" | undefined
>'cat' as const : "cat"
>'cat' : "cat"
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/callsOnComplexSignatures.types
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ function test5() {
}

var C: React.ComponentType<P1> | React.ComponentType<P2> = null as any;
>C : React.ComponentClass<P1, any> | React.StatelessComponent<P1> | React.ComponentClass<P2, any> | React.StatelessComponent<P2>
>C : React.ComponentType<P1> | React.ComponentType<P2>
>React : any
>React : any
>null as any : any
Expand All @@ -408,7 +408,7 @@ function test5() {
const a = <C p={true} />;
>a : JSX.Element
><C p={true} /> : JSX.Element
>C : React.ComponentClass<P1, any> | React.StatelessComponent<P1> | React.ComponentClass<P2, any> | React.StatelessComponent<P2>
>C : React.ComponentType<P1> | React.ComponentType<P2>
>p : true
>true : true
}
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/checkJsxChildrenProperty13.types
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ class Button extends React.Component<ButtonProp, any> {
>(<InnerButton {...this.props} children="hi"> <div>Hello World</div> </InnerButton>) : JSX.Element
><InnerButton {...this.props} children="hi"> <div>Hello World</div> </InnerButton> : JSX.Element
>InnerButton : typeof InnerButton
>this.props : ButtonProp & { children?: string | number | boolean | {} | React.ReactElement<any> | (string | number | boolean | any[] | React.ReactElement<any>)[] | undefined; }
>this.props : ButtonProp & { children?: React.ReactNode | undefined; }
>this : this
>props : ButtonProp & { children?: string | number | boolean | {} | React.ReactElement<any> | (string | number | boolean | any[] | React.ReactElement<any>)[] | undefined; }
>props : ButtonProp & { children?: React.ReactNode | undefined; }
>children : string

<div>Hello World</div>
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/checkJsxChildrenProperty3.types
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ class FetchUser extends React.Component<IFetchUserProps, any> {

? this.props.children(this.state.result)
>this.props.children(this.state.result) : JSX.Element
>this.props.children : ((user: IUser) => JSX.Element) | (((user: IUser) => JSX.Element) & string) | (((user: IUser) => JSX.Element) & number) | (((user: IUser) => JSX.Element) & false) | (((user: IUser) => JSX.Element) & true) | (((user: IUser) => JSX.Element) & React.ReactElement<any>) | (((user: IUser) => JSX.Element) & (string | number | boolean | any[] | React.ReactElement<any>)[])
>this.props.children : ((user: IUser) => JSX.Element) | (((user: IUser) => JSX.Element) & string) | (((user: IUser) => JSX.Element) & number) | (((user: IUser) => JSX.Element) & false) | (((user: IUser) => JSX.Element) & true) | (((user: IUser) => JSX.Element) & React.ReactElement<any>) | (((user: IUser) => JSX.Element) & (boolean | any[] | React.ReactChild)[])
>this.props : IFetchUserProps & { children?: React.ReactNode; }
>this : this
>props : IFetchUserProps & { children?: React.ReactNode; }
>children : ((user: IUser) => JSX.Element) | (((user: IUser) => JSX.Element) & string) | (((user: IUser) => JSX.Element) & number) | (((user: IUser) => JSX.Element) & false) | (((user: IUser) => JSX.Element) & true) | (((user: IUser) => JSX.Element) & React.ReactElement<any>) | (((user: IUser) => JSX.Element) & (string | number | boolean | any[] | React.ReactElement<any>)[])
>children : ((user: IUser) => JSX.Element) | (((user: IUser) => JSX.Element) & string) | (((user: IUser) => JSX.Element) & number) | (((user: IUser) => JSX.Element) & false) | (((user: IUser) => JSX.Element) & true) | (((user: IUser) => JSX.Element) & React.ReactElement<any>) | (((user: IUser) => JSX.Element) & (boolean | any[] | React.ReactChild)[])
>this.state.result : any
>this.state : any
>this : this
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
tests/cases/conformance/jsx/file.tsx(24,28): error TS2551: Property 'NAme' does not exist on type 'IUser'. Did you mean 'Name'?
tests/cases/conformance/jsx/file.tsx(36,15): error TS2322: Type '(user: IUser) => Element' is not assignable to type 'string | number | boolean | any[] | ReactElement<any>'.
tests/cases/conformance/jsx/file.tsx(36,15): error TS2322: Type '(user: IUser) => Element' is not assignable to type 'boolean | any[] | ReactChild'.
Type '(user: IUser) => Element' is missing the following properties from type 'ReactElement<any>': type, props
tests/cases/conformance/jsx/file.tsx(39,15): error TS2322: Type '(user: IUser) => Element' is not assignable to type 'string | number | boolean | any[] | ReactElement<any>'.
tests/cases/conformance/jsx/file.tsx(39,15): error TS2322: Type '(user: IUser) => Element' is not assignable to type 'boolean | any[] | ReactChild'.
Type '(user: IUser) => Element' is missing the following properties from type 'ReactElement<any>': type, props


Expand Down Expand Up @@ -50,7 +50,7 @@ tests/cases/conformance/jsx/file.tsx(39,15): error TS2322: Type '(user: IUser) =
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
) }
~~~~~~~~~~~~~
!!! error TS2322: Type '(user: IUser) => Element' is not assignable to type 'string | number | boolean | any[] | ReactElement<any>'.
!!! error TS2322: Type '(user: IUser) => Element' is not assignable to type 'boolean | any[] | ReactChild'.
!!! error TS2322: Type '(user: IUser) => Element' is missing the following properties from type 'ReactElement<any>': type, props
!!! related TS6212 tests/cases/conformance/jsx/file.tsx:36:15: Did you mean to call this expression?
{ user => (
Expand All @@ -59,7 +59,7 @@ tests/cases/conformance/jsx/file.tsx(39,15): error TS2322: Type '(user: IUser) =
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
) }
~~~~~~~~~~~~~
!!! error TS2322: Type '(user: IUser) => Element' is not assignable to type 'string | number | boolean | any[] | ReactElement<any>'.
!!! error TS2322: Type '(user: IUser) => Element' is not assignable to type 'boolean | any[] | ReactChild'.
!!! error TS2322: Type '(user: IUser) => Element' is missing the following properties from type 'ReactElement<any>': type, props
!!! related TS6212 tests/cases/conformance/jsx/file.tsx:39:15: Did you mean to call this expression?
</FetchUser>
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/checkJsxChildrenProperty4.types
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ class FetchUser extends React.Component<IFetchUserProps, any> {

? this.props.children(this.state.result)
>this.props.children(this.state.result) : JSX.Element
>this.props.children : ((user: IUser) => JSX.Element) | (((user: IUser) => JSX.Element) & string) | (((user: IUser) => JSX.Element) & number) | (((user: IUser) => JSX.Element) & false) | (((user: IUser) => JSX.Element) & true) | (((user: IUser) => JSX.Element) & React.ReactElement<any>) | (((user: IUser) => JSX.Element) & (string | number | boolean | any[] | React.ReactElement<any>)[])
>this.props.children : ((user: IUser) => JSX.Element) | (((user: IUser) => JSX.Element) & string) | (((user: IUser) => JSX.Element) & number) | (((user: IUser) => JSX.Element) & false) | (((user: IUser) => JSX.Element) & true) | (((user: IUser) => JSX.Element) & React.ReactElement<any>) | (((user: IUser) => JSX.Element) & (boolean | any[] | React.ReactChild)[])
>this.props : IFetchUserProps & { children?: React.ReactNode; }
>this : this
>props : IFetchUserProps & { children?: React.ReactNode; }
>children : ((user: IUser) => JSX.Element) | (((user: IUser) => JSX.Element) & string) | (((user: IUser) => JSX.Element) & number) | (((user: IUser) => JSX.Element) & false) | (((user: IUser) => JSX.Element) & true) | (((user: IUser) => JSX.Element) & React.ReactElement<any>) | (((user: IUser) => JSX.Element) & (string | number | boolean | any[] | React.ReactElement<any>)[])
>children : ((user: IUser) => JSX.Element) | (((user: IUser) => JSX.Element) & string) | (((user: IUser) => JSX.Element) & number) | (((user: IUser) => JSX.Element) & false) | (((user: IUser) => JSX.Element) & true) | (((user: IUser) => JSX.Element) & React.ReactElement<any>) | (((user: IUser) => JSX.Element) & (boolean | any[] | React.ReactChild)[])
>this.state.result : any
>this.state : any
>this : this
Expand Down
6 changes: 3 additions & 3 deletions tests/baselines/reference/controlFlowOptionalChain.types
Original file line number Diff line number Diff line change
Expand Up @@ -1882,12 +1882,12 @@ type Shape =
>radius : number

function getArea(shape?: Shape) {
>getArea : (shape?: { type: "rectangle"; width: number; height: number; } | { type: "circle"; radius: number; } | undefined) => number
>shape : { type: "rectangle"; width: number; height: number; } | { type: "circle"; radius: number; } | undefined
>getArea : (shape?: Shape | undefined) => number
>shape : Shape | undefined

switch (shape?.type) {
>shape?.type : "rectangle" | "circle" | undefined
>shape : { type: "rectangle"; width: number; height: number; } | { type: "circle"; radius: number; } | undefined
>shape : Shape | undefined
>type : "rectangle" | "circle" | undefined

case 'circle':
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/discriminantPropertyCheck.types
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,9 @@ export function foo(obj: Obj) {
>obj : Obj

switch (obj.key) {
>obj.key : "+" | "-" | "*" | "/"
>obj.key : Additive | Multiplicative
>obj : Obj
>key : "+" | "-" | "*" | "/"
>key : Additive | Multiplicative

case '+': {
>'+' : "+"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export type DiagnosticSeverity = 1 | 2 | 3 | 4;

export interface Diagnostic {
severity?: DiagnosticSeverity;
>severity : 1 | 2 | 3 | 4 | undefined
>severity : DiagnosticSeverity | undefined

code?: number | string;
>code : string | number | undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ const testFnTypes = {
*/
function testFn(input) {
>testFn : (input: testFnTypes.input) => number | null
>input : boolean | Function | myTypes.typeB
>input : boolean | myTypes.typeC

if (typeof input === 'number') {
>typeof input === 'number' : boolean
>typeof input : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>input : boolean | Function | myTypes.typeB
>input : boolean | myTypes.typeC
>'number' : "number"

return 2 * input;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ export interface ReactSelectProps<TValue = OptionValues> extends React.Props<Rea
* option component to render in dropdown
*/
optionComponent?: OptionComponentType<TValue>;
>optionComponent : React.ComponentClass<OptionComponentProps<TValue>, any> | React.StatelessComponent<OptionComponentProps<TValue>> | undefined
>optionComponent : React.ComponentType<OptionComponentProps<TValue>> | undefined

/**
* function which returns a custom way to render the options in the menu
Expand Down Expand Up @@ -973,7 +973,7 @@ export interface ReactSelectProps<TValue = OptionValues> extends React.Props<Rea
* value component to render
*/
valueComponent?: ValueComponentType<TValue>;
>valueComponent : React.ComponentClass<ValueComponentProps<TValue>, any> | React.StatelessComponent<ValueComponentProps<TValue>> | undefined
>valueComponent : React.ComponentType<ValueComponentProps<TValue>> | undefined

/**
* optional style to apply to the component wrapper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function f2() {
>false : false

type ElementOrArray = Element | Element[];
>ElementOrArray : string | false | (string | false)[]
>ElementOrArray : (string | false) | (string | false)[]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Odd, we shouldn't have needed the parentheses here. I assume its because the union is no longer flat?

Copy link
Member Author

@ahejlsberg ahejlsberg Jan 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That appears to be a bug in the type writer. It's trying to write Element, but Element is not globally reachable (it's a local type), so instead it prints string | false. It works fine when displaying quick info on the same code in the IDE, i.e. the displayed type is Element | Element[].


let el: Element = null as any;
>el : string | false
Expand All @@ -44,32 +44,32 @@ function f2() {
>null : null

let elOrA: ElementOrArray = null as any;
>elOrA : string | false | (string | false)[]
>elOrA : (string | false) | (string | false)[]
>null as any : any
>null : null

// Desired/actual: All OK
let a1: ElementOrArray = el;
>a1 : string | false | (string | false)[]
>a1 : (string | false) | (string | false)[]
>el : string | false

let a2: ElementOrArray = arr;
>a2 : string | false | (string | false)[]
>a2 : (string | false) | (string | false)[]
>arr : (string | false)[]

let a3: ElementOrArray = [el];
>a3 : string | false | (string | false)[]
>a3 : (string | false) | (string | false)[]
>[el] : (string | false)[]
>el : string | false

let a4: ElementOrArray = Array.isArray(elOrA) ? elOrA : [elOrA];
>a4 : string | false | (string | false)[]
>a4 : (string | false) | (string | false)[]
>Array.isArray(elOrA) ? elOrA : [elOrA] : (string | false)[]
>Array.isArray(elOrA) : boolean
>Array.isArray : (arg: any) => arg is any[]
>Array : ArrayConstructor
>isArray : (arg: any) => arg is any[]
>elOrA : string | false | (string | false)[]
>elOrA : (string | false) | (string | false)[]
>elOrA : (string | false)[]
>[elOrA] : (string | false)[]
>elOrA : string | false
Expand All @@ -78,7 +78,7 @@ function f2() {
// 3.0: Error
// 3.1: OK
let a5: ElementOrArray = [...Array.isArray(elOrA) ? elOrA : [elOrA]];
>a5 : string | false | (string | false)[]
>a5 : (string | false) | (string | false)[]
>[...Array.isArray(elOrA) ? elOrA : [elOrA]] : (string | false)[]
>...Array.isArray(elOrA) ? elOrA : [elOrA] : string | false
>Array.isArray(elOrA) ? elOrA : [elOrA] : (string | false)[]
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/observableInferenceCanBeMade.types
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ declare class Observable<T> implements Subscribable<T> {

function asObservable(input: string | ObservableInput<string>): Observable<string> {
>asObservable : (input: string | ObservableInput<string>) => Observable<string>
>input : string | Subscribable<never> | Subscribable<string>
>input : string | ObservableInput<string>

return typeof input === 'string' ? of(input) : from(input)
>typeof input === 'string' ? of(input) : from(input) : Observable<string>
>typeof input === 'string' : boolean
>typeof input : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>input : string | Subscribable<never> | Subscribable<string>
>input : string | ObservableInput<string>
>'string' : "string"
>of(input) : Observable<string>
>of : <T>(a: T) => Observable<T>
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/recursiveConditionalTypes.types
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ unbox({ value: { value: { get value() { return this; } }}}); // { readonly valu
>value : { readonly value: { readonly value: any; }; }
>{ get value() { return this; } } : { readonly value: { readonly value: any; }; }
>value : { readonly value: any; }
>this : { readonly value: any; } | { readonly value: { readonly value: any; }; } | Box<RecBox<{ readonly value: { readonly value: any; }; }>>
>this : { readonly value: any; } | RecBox<{ readonly value: { readonly value: any; }; }>

// Inference from nested instantiations of same generic types

Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/recursiveReverseMappedType.types
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function a<T>(l: Recur<T>[]): void {
>l : Recur<T>[]

const x: Recur<T> | undefined = join(l);
>x : (T extends unknown[] ? {} : { [K in keyof T]?: (T[K] extends unknown[] ? {} : { [K in keyof T[K]]?: (T[K][K] extends unknown[] ? {} : { [K in keyof T[K][K]]?: (T[K][K][K] extends unknown[] ? {} : { [K in keyof T[K][K][K]]?: (T[K][K][K][K] extends unknown[] ? {} : { [K in keyof T[K][K][K][K]]?: (T[K][K][K][K][K] extends unknown[] ? {} : { [K in keyof T[K][K][K][K][K]]?: (T[K][K][K][K][K][K] extends unknown[] ? {} : { [K in keyof T[K][K][K][K][K][K]]?: (T[K][K][K][K][K][K][K] extends unknown[] ? {} : { [K in keyof T[K][K][K][K][K][K][K]]?: (T[K][K][K][K][K][K][K][K] extends unknown[] ? {} : { [K in keyof T[K][K][K][K][K][K][K][K]]?: (T[K][K][K][K][K][K][K][K][K] extends unknown[] ? {} : { [K in keyof T[K][K][K][K][K][K][K][K][K]]?: (T[K][K][K][K][K][K][K][K][K][K] extends unknown[] ? {} : { [K in keyof T[K][K][K][K][K][K][K][K][K][K]]?: (T[K][K][K][K][K][K][K][K][K][K][K] extends unknown[] ? {} : any) | ["marker", ...Recur<T[K][K][K][K][K][K][K][K][K][K][K]>[]] | undefined; }) | ["marker", ...Recur<T[K][K][K][K][K][K][K][K][K][K]>[]] | undefined; }) | ["marker", ...Recur<T[K][K][K][K][K][K][K][K][K]>[]] | undefined; }) | ["marker", ...Recur<T[K][K][K][K][K][K][K][K]>[]] | undefined; }) | ["marker", ...Recur<T[K][K][K][K][K][K][K]>[]] | undefined; }) | ["marker", ...Recur<T[K][K][K][K][K][K]>[]] | undefined; }) | ["marker", ...Recur<T[K][K][K][K][K]>[]] | undefined; }) | ["marker", ...Recur<T[K][K][K][K]>[]] | undefined; }) | ["marker", ...Recur<T[K][K][K]>[]] | undefined; }) | ["marker", ...Recur<T[K][K]>[]] | undefined; }) | ["marker", ...Recur<T[K]>[]] | undefined; }) | ["marker", ...Recur<T>[]] | undefined
>x : Recur<T> | undefined
>join(l) : Recur<T>
>join : <T>(l: Recur<T>[]) => Recur<T>
>l : Recur<T>[]
Expand Down
Loading