8000 Support re-aliasing of type alias instantiations by ahejlsberg · Pull Request #42284 · microsoft/TypeScript · GitHub
[go: up one dir, main page]

Skip to content

Support re-aliasing of type alias instantiations #42284

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 5 commits into from
Jan 11, 2021
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 Jan 9, 2021
commit 54da2a43ad8bd6de18715407f34c0f9b90e6fdbc
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ type ExtendedMapper<HandledInputT, OutputT, ArgsT extends any[]> = (name : strin
>args : ArgsT

type a = ExtendedMapper<any, any, [any]>;
>a : ExtendedMapper<any, any, [any]>
>a : a

type b = ExtendedMapper<any, any, any[]>;
>b : ExtendedMapper<any, any, any[]>
>b : b

type test = a extends b ? "y" : "n"
>test : "y"
Expand All @@ -32,10 +32,10 @@ type ExtendedMapper1<HandledInputT, OutputT, ArgsT extends any[]> = (
);

type a1 = ExtendedMapper1<any, any, [any]>;
>a1 : ExtendedMapper1<any, any, [any]>
>a1 : a1

type b1 = ExtendedMapper1<any, any, any[]>;
>b1 : ExtendedMapper1<any, any, any[]>
>b1 : b1

type test1 = a1 extends b1 ? "y" : "n"
>test1 : "y"
Expand All @@ -56,10 +56,10 @@ type ExtendedMapper2<HandledInputT, OutputT, ArgsT extends any[]> = (
);

type a2 = ExtendedMapper2<any, any, [any]>;
>a2 : (name: string, mixed: any, args_0: any) => any
>a2 : a2

type b2 = ExtendedMapper2<any, any, any[]>;
>b2 : (name: string, mixed: any, ...args: any[]) => any
>b2 : b2

type test2 = a2 extends b2 ? "y" : "n"
>test2 : "y"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ export declare type TypeB = Merge<TypeA, {
b: string;
}>;
//// [index.d.ts]
import { TypeB } from './type-b';
export declare class Broken {
method(): import("./types").Merge<import("./type-a").TypeA, {
b: string;
}>;
method(): TypeB;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ export class Broken {
>Broken : Broken

method () {
>method : () => import("tests/cases/compiler/Uppercased_Dir/src/types").Merge<import("tests/cases/compiler/Uppercased_Dir/src/type-a").TypeA, { b: string; }>
>method : () => TypeB

return { } as TypeB;
>{ } as TypeB : import("tests/cases/compiler/Uppercased_Dir/src/types").Merge<import("tests/cases/compiler/Uppercased_Dir/src/type-a").TypeA, { b: string; }>
>{ } as TypeB : TypeB
>{ } : {}
}
}
Expand All @@ -21,7 +21,7 @@ import { TypeA } from './type-a';
>TypeA : any

export type TypeB = Merge<TypeA, {
>TypeB : Merge<TypeA, { b: string; }>
>TypeB : TypeB

b: string;
>b : string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export type Matching<InjectedProps, DecorationTargetProps> = {
};

export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
>Omit : Pick<T, Exclude<keyof T, K>>
>Omit : Omit<T, K>

export type InferableComponentEnhancerWithProps<TInjectedProps, TNeedsProps> =
>InferableComponentEnhancerWithProps : InferableComponentEnhancerWithProps<TInjectedProps, TNeedsProps>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
=== tests/cases/compiler/circularlySimplifyingConditionalTypesNoCrash.ts ===
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
>Omit : Pick<T, Exclude<keyof T, K>>
>Omit : Omit<T, K>

type Shared< // Circularly self constraining type, defered thanks to mapping
>Shared : Shared<InjectedProps, DecorationTargetProps>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export type ChannelType = Channel extends { type: infer R } ? R : never;
>type : R

type Omit<T, K extends keyof T> = Pick<
>Omit : Pick<T, ({ [P in keyof T]: P; } & { [P in K]: never; } & { [x: string]: never; })[keyof T]>
>Omit : Omit<T, K>

T,
({ [P in keyof T]: P } & { [P in K]: never } & { [x: string]: never })[keyof T]
Expand Down

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions tests/baselines/reference/conditionalTypes1.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ tests/cases/conformance/types/conditional/conditionalTypes1.ts(159,5): error TS2
tests/cases/conformance/types/conditional/conditionalTypes1.ts(160,5): error TS2322: Type 'T' is not assignable to type 'ZeroOf<T>'.
Type 'string | number' is not assignable to type 'ZeroOf<T>'.
Type 'string' is not assignable to type 'ZeroOf<T>'.
tests/cases/conformance/types/conditional/conditionalTypes1.ts(263,9): error TS2403: Subsequent variable declarations must have the same type. Variable 'z' must be of type 'T1', but here has type 'Foo<T & U>'.
tests/cases/conformance/types/conditional/conditionalTypes1.ts(263,9): error TS2403: Subsequent variable declarations must have the same type. Variable 'z' must be of type 'T1', but here has type 'T2'.
tests/cases/conformance/types/conditional/conditionalTypes1.ts(288,43): error TS2322: Type 'T95<U>' is not assignable to type 'T94<U>'.
Type 'number | boolean' is not assignable to type 'T94<U>'.
Type 'number' is not assignable to type 'T94<U>'.
Expand Down Expand Up @@ -398,7 +398,7 @@ tests/cases/conformance/types/conditional/conditionalTypes1.ts(288,43): error TS
var z: T1;
var z: T2; // Error, T2 is distributive, T1 isn't
~
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'z' must be of type 'T1', but here has type 'Foo<T & U>'.
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'z' must be of type 'T1', but here has type 'T2'.
!!! related TS6203 tests/cases/conformance/types/conditional/conditionalTypes1.ts:262:9: 'z' was also declared here.
}

Expand Down
72 changes: 36 additions & 36 deletions tests/baselines/reference/conditionalTypes1.types
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
=== tests/cases/conformance/types/conditional/conditionalTypes1.ts ===
type T00 = Exclude<"a" | "b" | "c" | "d", "a" | "c" | "f">; // "b" | "d"
>T00 : "b" | "d"
>T00 : T00

type T01 = Extract<"a" | "b" | "c" | "d", "a" | "c" | "f">; // "a" | "c"
>T01 : "a" | "c"
>T01 : T01

type T02 = Exclude<string | number | (() => void), Function>; // string | number
>T02 : string | number
>T02 : T02

type T03 = Extract<string | number | (() => void), Function>; // () => void
>T03 : () => void

type T04 = NonNullable<string | number | undefined>; // string | number
>T04 : string | number
>T04 : T04

type T05 = NonNullable<(() => string) | string[] | null | undefined>; // (() => string) | string[]
>T05 : (() => string) | string[]
>T05 : T05
>null : null

function f1<T>(x: T, y: NonNullable<T>) {
Expand Down Expand Up @@ -113,7 +113,7 @@ type T10 = Exclude<Options, { k: "a" | "b" }>; // { k: "c", c: boolean }
>k : "a" | "b"

type T11 = Extract<Options, { k: "a" | "b" }>; // { k: "a", a: number } | { k: "b", b: string }
>T11 : { k: "a"; a: number; } | { k: "b"; b: string; }
>T11 : T11
>k : "a" | "b"

type T12 = Exclude<Options, { k: "a" } | { k: "b" }>; // { k: "c", c: boolean }
Expand All @@ -122,12 +122,12 @@ type T12 = Exclude<Options, { k: "a" } | { k: "b" }>; // { k: "c", c: boolean }
>k : "b"

type T13 = Extract<Options, { k: "a" } | { k: "b" }>; // { k: "a", a: number } | { k: "b", b: string }
>T13 : { k: "a"; a: number; } | { k: "b"; b: string; }
>T13 : T13
>k : "a"
>k : "b"

type T14 = Exclude<Options, { q: "a" }>; // Options
>T14 : Options
>T14 : T14
>q : "a"

type T15 = Extract<Options, { q: "a" }>; // never
Expand All @@ -146,17 +146,17 @@ let x0 = f5("a"); // { k: "a", a: number }
>"a" : "a"

type OptionsOfKind<K extends Opt F438 ions["k"]> = Extract<Options, { k: K }>;
>OptionsOfKind : Extract<{ k: "a"; a: number; }, { k: K; }> | Extract<{ k: "b"; b: string; }, { k: K; }> | Extract<{ k: "c"; c: boolean; }, { k: K; }>
>OptionsOfKind : OptionsOfKind<K>
>k : K

type T16 = OptionsOfKind<"a" | "b">; // { k: "a", a: number } | { k: "b", b: string }
>T16 : { k: "a"; a: number; } | { k: "b"; b: string; }
>T16 : T16

type Select<T, K extends keyof T, V extends T[K]> = Extract<T, { [P in K]: V }>;
>Select : Extract<T, { [P in K]: V; }>
>Select : Select<T, K, V>

type T17 = Select<Options, "k", "a" | "b">; // // { k: "a", a: number } | { k: "b", b: string }
>T17 : { k: "a"; a: number; } | { k: "b"; b: string; }
>T17 : T17

type TypeName<T> =
>TypeName : TypeName<T>
Expand All @@ -169,7 +169,7 @@ type TypeName<T> =
"object";

type T20 = TypeName<string | (() => void)>; // "string" | "function"
>T20 : "string" | "function"
>T20 : T20

type T21 = TypeName<any>; // "string" | "number" | "boolean" | "undefined" | "function" | "object"
>T21 : "string" | "number" | "boolean" | "undefined" | "object" | "function"
Expand Down Expand Up @@ -230,19 +230,19 @@ type FunctionPropertyNames<T> = { [K in keyof T]: T[K] extends Function ? K : ne
>FunctionPropertyNames : FunctionPropertyNames<T>

type FunctionProperties<T> = Pick<T, FunctionPropertyNames<T>>;
>FunctionProperties : Pick<T, FunctionPropertyNames<T>>
>FunctionProperties : FunctionProperties<T>

type NonFunctionPropertyNames<T> = { [K in keyof T]: T[K] extends Function ? never : K }[keyof T];
>NonFunctionPropertyNames : NonFunctionPropertyNames<T>

type NonFunctionProperties<T> = Pick<T, NonFunctionPropertyNames<T>>;
>NonFunctionProperties : Pick<T, NonFunctionPropertyNames<T>>
>NonFunctionProperties : NonFunctionProperties<T>

type T30 = FunctionProperties<Part>;
>T30 : Pick<Part, "updatePart">
>T30 : T30

type T31 = NonFunctionProperties<Part>;
>T31 : Pick<Part, NonFunctionPropertyNames<Part>>
>T31 : T31

function f7<T>(x: T, y: FunctionProperties<T>, z: NonFunctionProperties<T>) {
>f7 : <T>(x: T, y: FunctionProperties<T>, z: NonFunctionProperties<T>) => void
Expand Down Expand Up @@ -523,20 +523,20 @@ type If<C extends boolean, T, F> = C extends true ? T : F;
>true : true

type Not<C extends boolean> = If<C, false, true>;
>Not : If<C, false, true>
>Not : Not<C>
>false : false
>true : true

type And<A extends boolean, B extends boolean> = If<A, B, false>;
>And : If<A, B, false>
>And : And<A, B>
>false : false

type Or<A extends boolean, B extends boolean> = If<A, true, B>;
>Or : If<A, true, B>
>Or : Or<A, B>
>true : true

type IsString<T> = Extends<T, string>;
>IsString : Extends<T, string>
>IsString : IsString<T>

type Q1 = IsString<number>; // false
>Q1 : false
Expand All @@ -559,7 +559,7 @@ type N2 = Not<true>; // false
>true : true

type N3 = Not<boolean>; // boolean
>N3 : boolean
>N3 : N3

type A1 = And<false, false>; // false
>A1 : false
Expand Down Expand Up @@ -590,15 +590,15 @@ type A6 = And<false, boolean>; // false
>false : false

type A7 = And<boolean, true>; // boolean
>A7 : boolean
>A7 : A7
>true : true

type A8 = And<true, boolean>; // boolean
>A8 : boolean
>true : true

type A9 = And<boolean, boolean>; // boolean
>A9 : boolean
>A9 : A9

type O1 = Or<false, false>; // false
>O1 : false
Expand All @@ -621,7 +621,7 @@ type O4 = Or<true, true>; // true
>true : true

type O5 = Or<boolean, false>; // boolean
>O5 : boolean
>O5 : O5
>false : false

type O6 = Or<false, boolean>; // boolean
Expand All @@ -637,7 +637,7 @@ type O8 = Or<true, boolean>; // true
>true : true

type O9 = Or<boolean, boolean>; // boolean
>O9 : boolean
>O9 : O9

type T40 = never extends never ? true : false; // true
>T40 : true
Expand Down Expand Up @@ -785,7 +785,7 @@ const convert = <U>(value: Foo<U>): Bar<U> => value;
>value : Foo<U>

type Baz<T> = Foo<T>;
>Baz : Foo<T>
>Baz : Baz<T>

const convert2 = <T>(value: Foo<T>): Baz<T> => value;
>convert2 : <T>(value: Foo<T>) => Foo<T>
Expand Down Expand Up @@ -816,7 +816,7 @@ function f32<T, U>() {
>T1 : T & U extends string ? boolean : number

type T2 = Foo<T & U>;
>T2 : Foo<T & U>
>T2 : T & U extends string ? boolean : number

var z: T1;
>z : T & U extends string ? boolean : number
Expand All @@ -829,16 +829,16 @@ function f33<T, U>() {
>f33 : <T, U>() => void

type T1 = Foo<T & U>;
>T1 : Foo<T & U>
>T1 : T & U extends string ? boolean : number

type T2 = Bar<T & U>;
>T2 : Bar<T & U>
>T2 : T & U extends string ? boolean : number

var z: T1;
>z : Foo<T & U>
>z : T & U extends string ? boolean : number

var z: T2;
>z : Foo<T & U>
>z : T & U extends string ? boolean : number
}

// Repro from #21823
Expand Down Expand Up @@ -971,19 +971,19 @@ type c2 = B2['c']; // 'c' | 'b'
// Repro from #21929

type NonFooKeys1<T extends object> = OldDiff<keyof T, 'foo'>;
>NonFooKeys1 : OldDiff<keyof T, "foo">
>NonFooKeys1 : NonFooKeys1<T>

type NonFooKeys2<T extends object> = Exclude<keyof T, 'foo'>;
>NonFooKeys2 : Exclude<keyof T, "foo">
>NonFooKeys2 : NonFooKeys2<T>

type Test1 = NonFooKeys1<{foo: 1, bar: 2, baz: 3}>; // "bar" | "baz"
>Test1 : OldDiff<"foo" | "bar" | "baz", "foo">
>Test1 : Test1
>foo : 1
>bar : 2
>baz : 3

type Test2 = NonFooKeys2<{foo: 1, bar: 2, baz: 3}>; // "bar" | "baz"
>Test2 : "bar" | "baz"
>Test2 : Test2
>foo : 1
>bar : 2
>baz : 3
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/conditionalTypes2.types
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ declare type GetPropertyNamesOfType<T, RestrictToType> = {
}[Extract<keyof T, string>];

declare type GetAllPropertiesOfType<T, RestrictToType> = Pick<
>GetAllPropertiesOfType : Pick<T, GetPropertyNamesOfType<Required<T>, RestrictToType>>
>GetAllPropertiesOfType : GetAllPropertiesOfType<T, RestrictToType>

T,
GetPropertyNamesOfType<Required<T>, RestrictToType>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Result } from "lib/result";
>Result : any

export type T<T> = Result<Error, T>;
>T : Result<Error, T>
>T : import("tests/cases/compiler/src/datastore_result").T<T>

=== tests/cases/compiler/src/conditional_directive_field.ts ===
import * as DatastoreResult from "src/datastore_result";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
=== /Helpers.ts ===
export type StringKeyOf<TObj> = Extract<string, keyof TObj>;
>StringKeyOf : Extract<string, keyof TObj>
>StringKeyOf : StringKeyOf<TObj>

=== /FromFactor.ts ===
export type RowToColumns<TColumns> = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ exports.fun2 = bbb_1.create();


//// [index.d.ts]
export declare const fun: () => import("./bbb").INode<import("./lib").G<import("./lib").E>>;
export declare const fun2: () => import("./bbb").INode<import("./lib").G<import("./lib").E.A>>;
import { T, Q } from "./lib";
export declare const fun: () => import("./bbb").INode<T>;
export declare const fun2: () => import("./bbb").INode<Q>;
Loading
0