Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c456bbd

Browse filesBrowse files
authored
Support re-aliasing of type alias instantiations (#42284)
* New aliases for type alias instantiations * New aliases for conditional, mapped, and anonymous object type instantiations * Accept new baselines * Fix issues with re-aliasing * Accept new baselines
1 parent 1ecf228 commit c456bbd
Copy full SHA for c456bbd

86 files changed

+495-438Lines changed: 495 additions & 438 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/compiler/checker.ts‎

Copy file name to clipboardExpand all lines: src/compiler/checker.ts
+66-42Lines changed: 66 additions & 42 deletions
Large diffs are not rendered by default.
Collapse file

‎src/compiler/types.ts‎

Copy file name to clipboardExpand all lines: src/compiler/types.ts
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4745,6 +4745,8 @@ namespace ts {
47454745
typeParameters?: TypeParameter[]; // Type parameters of type alias (undefined if non-generic)
47464746
outerTypeParameters?: TypeParameter[]; // Outer type parameters of anonymous object type
47474747
instantiations?: ESMap<string, Type>; // Instantiations of generic type alias (undefined if non-generic)
4748+
aliasSymbol?: Symbol; // Alias associated with generic type alias instantiation
4749+
aliasTypeArguments?: readonly Type[] // Alias type arguments (if any)
47484750
inferredClassSymbol?: ESMap<SymbolId, TransientSymbol>; // Symbol of an inferred ES5 constructor function
47494751
mapper?: TypeMapper; // Type mapper for instantiation alias
47504752
referenced?: boolean; // True if alias symbol has been referenced as a value that can be emitted
Collapse file

‎tests/baselines/reference/aliasOfGenericFunctionWithRestBehavedSameAsUnaliased.types‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/aliasOfGenericFunctionWithRestBehavedSameAsUnaliased.types
+6-6Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ type ExtendedMapper<HandledInputT, OutputT, ArgsT extends any[]> = (name : strin
88
>args : ArgsT
99

1010
type a = ExtendedMapper<any, any, [any]>;
11-
>a : ExtendedMapper<any, any, [any]>
11+
>a : a
1212

1313
type b = ExtendedMapper<any, any, any[]>;
14-
>b : ExtendedMapper<any, any, any[]>
14+
>b : b
1515

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

3434
type a1 = ExtendedMapper1<any, any, [any]>;
35-
>a1 : ExtendedMapper1<any, any, [any]>
35+
>a1 : a1
3636

3737
type b1 = ExtendedMapper1<any, any, any[]>;
38-
>b1 : ExtendedMapper1<any, any, any[]>
38+
>b1 : b1
3939

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

5858
type a2 = ExtendedMapper2<any, any, [any]>;
59-
>a2 : (name: string, mixed: any, args_0: any) => any
59+
>a2 : a2
6060

6161
type b2 = ExtendedMapper2<any, any, any[]>;
62-
>b2 : (name: string, mixed: any, ...args: any[]) => any
62+
>b2 : b2
6363

6464
type test2 = a2 extends b2 ? "y" : "n"
6565
>test2 : "y"
Collapse file

‎tests/baselines/reference/caseInsensitiveFileSystemWithCapsImportTypeDeclarations.js‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/caseInsensitiveFileSystemWithCapsImportTypeDeclarations.js
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ export declare type TypeB = Merge<TypeA, {
6060
b: string;
6161
}>;
6262
//// [index.d.ts]
63+
import { TypeB } from './type-b';
6364
export declare class Broken {
64-
method(): import("./types").Merge<import("./type-a").TypeA, {
65-
b: string;
66-
}>;
65+
method(): TypeB;
6766
}
Collapse file

‎tests/baselines/reference/caseInsensitiveFileSystemWithCapsImportTypeDeclarations.types‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/caseInsensitiveFileSystemWithCapsImportTypeDeclarations.types
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ export class Broken {
66
>Broken : Broken
77

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

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

2323
export type TypeB = Merge<TypeA, {
24-
>TypeB : Merge<TypeA, { b: string; }>
24+
>TypeB : TypeB
2525

2626
b: string;
2727
>b : string
Collapse file

‎tests/baselines/reference/circularlyConstrainedMappedTypeContainingConditionalNoInfiniteInstantiationDepth.types‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/circularlyConstrainedMappedTypeContainingConditionalNoInfiniteInstantiationDepth.types
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export type Matching<InjectedProps, DecorationTargetProps> = {
113113
};
114114

115115
export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
116-
>Omit : Pick<T, Exclude<keyof T, K>>
116+
>Omit : Omit<T, K>
117117

118118
export type InferableComponentEnhancerWithProps<TInjectedProps, TNeedsProps> =
119119
>InferableComponentEnhancerWithProps : InferableComponentEnhancerWithProps<TInjectedProps, TNeedsProps>
Collapse file

‎tests/baselines/reference/circularlySimplifyingConditionalTypesNoCrash.types‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/circularlySimplifyingConditionalTypesNoCrash.types
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
=== tests/cases/compiler/circularlySimplifyingConditionalTypesNoCrash.ts ===
22
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
3-
>Omit : Pick<T, Exclude<keyof T, K>>
3+
>Omit : Omit<T, K>
44

55
type Shared< // Circularly self constraining type, defered thanks to mapping
66
>Shared : Shared<InjectedProps, DecorationTargetProps>
Collapse file

‎tests/baselines/reference/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.types‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.types
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export type ChannelType = Channel extends { type: infer R } ? R : never;
2929
>type : R
3030

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

3434
T,
3535
({ [P in keyof T]: P } & { [P in K]: never } & { [x: string]: never })[keyof T]
Collapse file

‎tests/baselines/reference/conditionalTypeDiscriminatingLargeUnionRegularTypeFetchingSpeedReasonable.types‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/conditionalTypeDiscriminatingLargeUnionRegularTypeFetchingSpeedReasonable.types
+2-2Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.
Collapse file

‎tests/baselines/reference/conditionalTypes1.errors.txt‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/conditionalTypes1.errors.txt
+34-14Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,24 @@ tests/cases/conformance/types/conditional/conditionalTypes1.ts(29,5): error TS23
1313
tests/cases/conformance/types/conditional/conditionalTypes1.ts(30,9): error TS2322: Type 'T["x"]' is not assignable to type 'string'.
1414
Type 'string | undefined' is not assignable to type 'string'.
1515
Type 'undefined' is not assignable to type 'string'.
16-
tests/cases/conformance/types/conditional/conditionalTypes1.ts(103,5): error TS2322: Type 'Pick<T, FunctionPropertyNames<T>>' is not assignable to type 'T'.
17-
'T' could be instantiated with an arbitrary type which could be unrelated to 'Pick<T, FunctionPropertyNames<T>>'.
18-
tests/cases/conformance/types/conditional/conditionalTypes1.ts(104,5): error TS2322: Type 'Pick<T, NonFunctionPropertyNames<T>>' is not assignable to type 'T'.
19-
'T' could be instantiated with an arbitrary type which could be unrelated to 'Pick<T, NonFunctionPropertyNames<T>>'.
20-
tests/cases/conformance/types/conditional/conditionalTypes1.ts(106,5): error TS2322: Type 'Pick<T, NonFunctionPropertyNames<T>>' is not assignable to type 'Pick<T, FunctionPropertyNames<T>>'.
16+
tests/cases/conformance/types/conditional/conditionalTypes1.ts(103,5): error TS2322: Type 'FunctionProperties<T>' is not assignable to type 'T'.
17+
'T' could be instantiated with an arbitrary type which could be unrelated to 'FunctionProperties<T>'.
18+
tests/cases/conformance/types/conditional/conditionalTypes1.ts(104,5): error TS2322: Type 'NonFunctionProperties<T>' is not assignable to type 'T'.
19+
'T' could be instantiated with an arbitrary type which could be unrelated to 'NonFunctionProperties<T>'.
20+
tests/cases/conformance/types/conditional/conditionalTypes1.ts(106,5): error TS2322: Type 'NonFunctionProperties<T>' is not assignable to type 'FunctionProperties<T>'.
2121
Type 'FunctionPropertyNames<T>' is not assignable to type 'NonFunctionPropertyNames<T>'.
22-
tests/cases/conformance/types/conditional/conditionalTypes1.ts(108,5): error TS2322: Type 'Pick<T, FunctionPropertyNames<T>>' is not assignable to type 'Pick<T, NonFunctionPropertyNames<T>>'.
22+
Type 'keyof T' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'.
23+
Type 'string | number | symbol' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'.
24+
Type 'string' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'.
25+
Type 'keyof T' is not assignable to type 'never'.
26+
Type 'string | number | symbol' is not assignable to type 'never'.
27+
Type 'string' is not assignable to type 'never'.
28+
tests/cases/conformance/types/conditional/conditionalTypes1.ts(108,5): error TS2322: Type 'FunctionProperties<T>' is not assignable to type 'NonFunctionProperties<T>'.
2329
Type 'NonFunctionPropertyNames<T>' is not assignable to type 'FunctionPropertyNames<T>'.
30+
Type 'keyof T' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'.
31+
Type 'string | number | symbol' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'.
32+
Type 'string' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'.
33+
Type 'keyof T' is not assignable to type 'never'.
2434
tests/cases/conformance/types/conditional/conditionalTypes1.ts(114,5): error TS2322: Type 'keyof T' is not assignable to type 'FunctionPropertyNames<T>'.
2535
Type 'string | number | symbol' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'.
2636
Type 'string' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'.
@@ -52,7 +62,7 @@ tests/cases/conformance/types/conditional/conditionalTypes1.ts(159,5): error TS2
5262
tests/cases/conformance/types/conditional/conditionalTypes1.ts(160,5): error TS2322: Type 'T' is not assignable to type 'ZeroOf<T>'.
5363
Type 'string | number' is not assignable to type 'ZeroOf<T>'.
5464
Type 'string' is not assignable to type 'ZeroOf<T>'.
55-
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>'.
65+
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'.
5666
tests/cases/conformance/types/conditional/conditionalTypes1.ts(288,43): error TS2322: Type 'T95<U>' is not assignable to type 'T94<U>'.
5767
Type 'number | boolean' is not assignable to type 'T94<U>'.
5868
Type 'number' is not assignable to type 'T94<U>'.
@@ -185,22 +195,32 @@ tests/cases/conformance/types/conditional/conditionalTypes1.ts(288,43): error TS
185195
function f7<T>(x: T, y: FunctionProperties<T>, z: NonFunctionProperties<T>) {
186196
x = y; // Error
187197
~
188-
!!! error TS2322: Type 'Pick<T, FunctionPropertyNames<T>>' is not assignable to type 'T'.
189-
!!! error TS2322: 'T' could be instantiated with an arbitrary type which could be unrelated to 'Pick<T, FunctionPropertyNames<T>>'.
198+
!!! error TS2322: Type 'FunctionProperties<T>' is not assignable to type 'T'.
199+
!!! error TS2322: 'T' could be instantiated with an arbitrary type which could be unrelated to 'FunctionProperties<T>'.
190200
x = z; // Error
191201
~
192-
!!! error TS2322: Type 'Pick<T, NonFunctionPropertyNames<T>>' is not assignable to type 'T'.
193-
!!! error TS2322: 'T' could be instantiated with an arbitrary type which could be unrelated to 'Pick<T, NonFunctionPropertyNames<T>>'.
202+
!!! error TS2322: Type 'NonFunctionProperties<T>' is not assignable to type 'T'.
203+
!!! error TS2322: 'T' could be instantiated with an arbitrary type which could be unrelated to 'NonFunctionProperties<T>'.
194204
y = x;
195205
y = z; // Error
196206
~
197-
!!! error TS2322: Type 'Pick<T, NonFunctionPropertyNames<T>>' is not assignable to type 'Pick<T, FunctionPropertyNames<T>>'.
207+
!!! error TS2322: Type 'NonFunctionProperties<T>' is not assignable to type 'FunctionProperties<T>'.
198208
!!! error TS2322: Type 'FunctionPropertyNames<T>' is not assignable to type 'NonFunctionPropertyNames<T>'.
209+
!!! error TS2322: Type 'keyof T' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'.
210+
!!! error TS2322: Type 'string | number | symbol' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'.
211+
!!! error TS2322: Type 'string' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'.
212+
!!! error TS2322: Type 'keyof T' is not assignable to type 'never'.
213+
!!! error TS2322: Type 'string | number | symbol' is not assignable to type 'never'.
214+
!!! error TS2322: Type 'string' is not assignable to type 'never'.
199215
z = x;
200216
z = y; // Error
201217
~
202-
!!! error TS2322: Type 'Pick<T, FunctionPropertyNames<T>>' is not assignable to type 'Pick<T, NonFunctionPropertyNames<T>>'.
218+
!!! error TS2322: Type 'FunctionProperties<T>' is not assignable to type 'NonFunctionProperties<T>'.
203219
!!! error TS2322: Type 'NonFunctionPropertyNames<T>' is not assignable to type 'FunctionPropertyNames<T>'.
220+
!!! error TS2322: Type 'keyof T' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'.
221+
!!! error TS2322: Type 'string | number | symbol' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'.
222+
!!! error TS2322: Type 'string' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'.
223+
!!! error TS2322: Type 'keyof T' is not assignable to type 'never'.
204224
}
205225

206226
function f8<T>(x: keyof T, y: FunctionPropertyNames<T>, z: NonFunctionPropertyNames<T>) {
@@ -398,7 +418,7 @@ tests/cases/conformance/types/conditional/conditionalTypes1.ts(288,43): error TS
398418
var z: T1;
399419
var z: T2; // Error, T2 is distributive, T1 isn't
400420
~
401-
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'z' must be of type 'T1', but here has type 'Foo<T & U>'.
421+
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'z' must be of type 'T1', but here has type 'T2'.
402422
!!! related TS6203 tests/cases/conformance/types/conditional/conditionalTypes1.ts:262:9: 'z' was also declared here.
403423
}
404424

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.