forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve contextually typed parameters with initializers (microsoft#56506
- Loading branch information
Showing
15 changed files
with
538 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...ypedParametersWithInitializers.errors.txt → ...pedParametersWithInitializers1.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
374 changes: 187 additions & 187 deletions
374
...lyTypedParametersWithInitializers.symbols → ...yTypedParametersWithInitializers1.symbols
Large diffs are not rendered by default.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
...allyTypedParametersWithInitializers.types → ...llyTypedParametersWithInitializers1.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
tests/baselines/reference/contextuallyTypedParametersWithInitializers2.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
//// [tests/cases/compiler/contextuallyTypedParametersWithInitializers2.ts] //// | ||
|
||
=== contextuallyTypedParametersWithInitializers2.ts === | ||
declare function test1< | ||
>test1 : Symbol(test1, Decl(contextuallyTypedParametersWithInitializers2.ts, 0, 0)) | ||
|
||
TContext, | ||
>TContext : Symbol(TContext, Decl(contextuallyTypedParametersWithInitializers2.ts, 0, 23)) | ||
|
||
TMethods extends Record<string, (ctx: TContext, ...args: never[]) => unknown>, | ||
>TMethods : Symbol(TMethods, Decl(contextuallyTypedParametersWithInitializers2.ts, 1, 11)) | ||
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) | ||
>ctx : Symbol(ctx, Decl(contextuallyTypedParametersWithInitializers2.ts, 2, 35)) | ||
>TContext : Symbol(TContext, Decl(contextuallyTypedParametersWithInitializers2.ts, 0, 23)) | ||
>args : Symbol(args, Decl(contextuallyTypedParametersWithInitializers2.ts, 2, 49)) | ||
|
||
>(context: TContext, methods: TMethods): void; | ||
>context : Symbol(context, Decl(contextuallyTypedParametersWithInitializers2.ts, 3, 2)) | ||
>TContext : Symbol(TContext, Decl(contextuallyTypedParametersWithInitializers2.ts, 0, 23)) | ||
>methods : Symbol(methods, Decl(contextuallyTypedParametersWithInitializers2.ts, 3, 20)) | ||
>TMethods : Symbol(TMethods, Decl(contextuallyTypedParametersWithInitializers2.ts, 1, 11)) | ||
|
||
test1( | ||
>test1 : Symbol(test1, Decl(contextuallyTypedParametersWithInitializers2.ts, 0, 0)) | ||
{ | ||
count: 0, | ||
>count : Symbol(count, Decl(contextuallyTypedParametersWithInitializers2.ts, 6, 3)) | ||
|
||
}, | ||
{ | ||
checkLimit: (ctx, max = 500) => {}, | ||
>checkLimit : Symbol(checkLimit, Decl(contextuallyTypedParametersWithInitializers2.ts, 9, 3)) | ||
>ctx : Symbol(ctx, Decl(contextuallyTypedParametersWithInitializers2.ts, 10, 17)) | ||
>max : Symbol(max, Decl(contextuallyTypedParametersWithInitializers2.ts, 10, 21)) | ||
|
||
hasAccess: (ctx, user: { name: string }) => {}, | ||
>hasAccess : Symbol(hasAccess, Decl(contextuallyTypedParametersWithInitializers2.ts, 10, 39)) | ||
>ctx : Symbol(ctx, Decl(contextuallyTypedParametersWithInitializers2.ts, 11, 16)) | ||
>user : Symbol(user, Decl(contextuallyTypedParametersWithInitializers2.ts, 11, 20)) | ||
>name : Symbol(name, Decl(contextuallyTypedParametersWithInitializers2.ts, 11, 28)) | ||
|
||
}, | ||
); | ||
|
||
declare const num: number; | ||
>num : Symbol(num, Decl(contextuallyTypedParametersWithInitializers2.ts, 15, 13)) | ||
|
||
const test2: (arg: 1 | 2) => void = (arg = num) => {}; | ||
>test2 : Symbol(test2, Decl(contextuallyTypedParametersWithInitializers2.ts, 16, 5)) | ||
>arg : Symbol(arg, Decl(contextuallyTypedParametersWithInitializers2.ts, 16, 14)) | ||
>arg : Symbol(arg, Decl(contextuallyTypedParametersWithInitializers2.ts, 16, 37)) | ||
>num : Symbol(num, Decl(contextuallyTypedParametersWithInitializers2.ts, 15, 13)) | ||
|
||
const test3: (arg: number) => void = (arg = 1) => {}; | ||
>test3 : Symbol(test3, Decl(contextuallyTypedParametersWithInitializers2.ts, 18, 5)) | ||
>arg : Symbol(arg, Decl(contextuallyTypedParametersWithInitializers2.ts, 18, 14)) | ||
>arg : Symbol(arg, Decl(contextuallyTypedParametersWithInitializers2.ts, 18, 38)) | ||
|
63 changes: 63 additions & 0 deletions
63
tests/baselines/reference/contextuallyTypedParametersWithInitializers2.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
//// [tests/cases/compiler/contextuallyTypedParametersWithInitializers2.ts] //// | ||
|
||
=== contextuallyTypedParametersWithInitializers2.ts === | ||
declare function test1< | ||
>test1 : <TContext, TMethods extends Record<string, (ctx: TContext, ...args: never[]) => unknown>>(context: TContext, methods: TMethods) => void | ||
|
||
TContext, | ||
TMethods extends Record<string, (ctx: TContext, ...args: never[]) => unknown>, | ||
>ctx : TContext | ||
>args : never[] | ||
|
||
>(context: TContext, methods: TMethods): void; | ||
>context : TContext | ||
>methods : TMethods | ||
|
||
test1( | ||
>test1( { count: 0, }, { checkLimit: (ctx, max = 500) => {}, hasAccess: (ctx, user: { name: string }) => {}, },) : void | ||
>test1 : <TContext, TMethods extends Record<string, (ctx: TContext, ...args: never[]) => unknown>>(context: TContext, methods: TMethods) => void | ||
{ | ||
>{ count: 0, } : { count: number; } | ||
|
||
count: 0, | ||
>count : number | ||
>0 : 0 | ||
|
||
}, | ||
{ | ||
>{ checkLimit: (ctx, max = 500) => {}, hasAccess: (ctx, user: { name: string }) => {}, } : { checkLimit: (ctx: { count: number; }, max?: number) => void; hasAccess: (ctx: { count: number; }, user: { name: string;}) => void; } | ||
|
||
checkLimit: (ctx, max = 500) => {}, | ||
>checkLimit : (ctx: { count: number; }, max?: number) => void | ||
>(ctx, max = 500) => {} : (ctx: { count: number; }, max?: number) => void | ||
>ctx : { count: number; } | ||
>max : number | ||
>500 : 500 | ||
|
||
hasAccess: (ctx, user: { name: string }) => {}, | ||
>hasAccess : (ctx: { count: number; }, user: { name: string;}) => void | ||
>(ctx, user: { name: string }) => {} : (ctx: { count: number; }, user: { name: string;}) => void | ||
>ctx : { count: number; } | ||
>user : { name: string; } | ||
>name : string | ||
|
||
}, | ||
); | ||
|
||
declare const num: number; | ||
>num : number | ||
|
||
const test2: (arg: 1 | 2) => void = (arg = num) => {}; | ||
>test2 : (arg: 1 | 2) => void | ||
>arg : 1 | 2 | ||
>(arg = num) => {} : (arg?: number) => void | ||
>arg : number | ||
>num : number | ||
|
||
const test3: (arg: number) => void = (arg = 1) => {}; | ||
>test3 : (arg: number) => void | ||
>arg : number | ||
>(arg = 1) => {} : (arg?: number) => void | ||
>arg : number | ||
>1 : 1 | ||
|
40 changes: 40 additions & 0 deletions
40
tests/baselines/reference/contextuallyTypedParametersWithInitializers3.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//// [tests/cases/compiler/contextuallyTypedParametersWithInitializers3.ts] //// | ||
|
||
=== contextuallyTypedParametersWithInitializers3.ts === | ||
type CanvasDirection = "RIGHT" | "LEFT"; | ||
>CanvasDirection : Symbol(CanvasDirection, Decl(contextuallyTypedParametersWithInitializers3.ts, 0, 0)) | ||
|
||
interface GraphActions { | ||
>GraphActions : Symbol(GraphActions, Decl(contextuallyTypedParametersWithInitializers3.ts, 0, 40)) | ||
|
||
setDirection: (direction: CanvasDirection) => void; | ||
>setDirection : Symbol(GraphActions.setDirection, Decl(contextuallyTypedParametersWithInitializers3.ts, 2, 24)) | ||
>direction : Symbol(direction, Decl(contextuallyTypedParametersWithInitializers3.ts, 3, 17)) | ||
>CanvasDirection : Symbol(CanvasDirection, Decl(contextuallyTypedParametersWithInitializers3.ts, 0, 0)) | ||
} | ||
|
||
export declare function create<T>(config: T): void; | ||
>create : Symbol(create, Decl(contextuallyTypedParametersWithInitializers3.ts, 4, 1)) | ||
>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers3.ts, 6, 31)) | ||
>config : Symbol(config, Decl(contextuallyTypedParametersWithInitializers3.ts, 6, 34)) | ||
>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers3.ts, 6, 31)) | ||
|
||
declare function takesDirection(direction: CanvasDirection): void; | ||
>takesDirection : Symbol(takesDirection, Decl(contextuallyTypedParametersWithInitializers3.ts, 6, 51)) | ||
>direction : Symbol(direction, Decl(contextuallyTypedParametersWithInitializers3.ts, 8, 32)) | ||
>CanvasDirection : Symbol(CanvasDirection, Decl(contextuallyTypedParametersWithInitializers3.ts, 0, 0)) | ||
|
||
create<GraphActions>({ | ||
>create : Symbol(create, Decl(contextuallyTypedParametersWithInitializers3.ts, 4, 1)) | ||
>GraphActions : Symbol(GraphActions, Decl(contextuallyTypedParametersWithInitializers3.ts, 0, 40)) | ||
|
||
setDirection: (direction = "RIGHT") => { | ||
>setDirection : Symbol(setDirection, Decl(contextuallyTypedParametersWithInitializers3.ts, 10, 22)) | ||
>direction : Symbol(direction, Decl(contextuallyTypedParametersWithInitializers3.ts, 11, 17)) | ||
|
||
takesDirection(direction); | ||
>takesDirection : Symbol(takesDirection, Decl(contextuallyTypedParametersWithInitializers3.ts, 6, 51)) | ||
>direction : Symbol(direction, Decl(contextuallyTypedParametersWithInitializers3.ts, 11, 17)) | ||
|
||
}, | ||
}); |
38 changes: 38 additions & 0 deletions
38
tests/baselines/reference/contextuallyTypedParametersWithInitializers3.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//// [tests/cases/compiler/contextuallyTypedParametersWithInitializers3.ts] //// | ||
|
||
=== contextuallyTypedParametersWithInitializers3.ts === | ||
type CanvasDirection = "RIGHT" | "LEFT"; | ||
>CanvasDirection : "RIGHT" | "LEFT" | ||
|
||
interface GraphActions { | ||
setDirection: (direction: CanvasDirection) => void; | ||
>setDirection : (direction: CanvasDirection) => void | ||
>direction : CanvasDirection | ||
} | ||
|
||
export declare function create<T>(config: T): void; | ||
>create : <T>(config: T) => void | ||
>config : T | ||
|
||
declare function takesDirection(direction: CanvasDirection): void; | ||
>takesDirection : (direction: CanvasDirection) => void | ||
>direction : CanvasDirection | ||
|
||
create<GraphActions>({ | ||
>create<GraphActions>({ setDirection: (direction = "RIGHT") => { takesDirection(direction); },}) : void | ||
>create : <T>(config: T) => void | ||
>{ setDirection: (direction = "RIGHT") => { takesDirection(direction); },} : { setDirection: (direction?: CanvasDirection) => void; } | ||
|
||
setDirection: (direction = "RIGHT") => { | ||
>setDirection : (direction?: CanvasDirection) => void | ||
>(direction = "RIGHT") => { takesDirection(direction); } : (direction?: CanvasDirection) => void | ||
>direction : CanvasDirection | ||
>"RIGHT" : "RIGHT" | ||
|
||
takesDirection(direction); | ||
>takesDirection(direction) : void | ||
>takesDirection : (direction: CanvasDirection) => void | ||
>direction : CanvasDirection | ||
|
||
}, | ||
}); |
38 changes: 38 additions & 0 deletions
38
tests/baselines/reference/contextuallyTypedParametersWithInitializers4.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//// [tests/cases/compiler/contextuallyTypedParametersWithInitializers4.ts] //// | ||
|
||
=== contextuallyTypedParametersWithInitializers4.ts === | ||
declare function test< | ||
>test : Symbol(test, Decl(contextuallyTypedParametersWithInitializers4.ts, 0, 0)) | ||
|
||
TContext, | ||
>TContext : Symbol(TContext, Decl(contextuallyTypedParametersWithInitializers4.ts, 0, 22)) | ||
|
||
TMethods extends Record<string, (ctx: TContext, ...args: (1 | 2)[]) => unknown>, | ||
>TMethods : Symbol(TMethods, Decl(contextuallyTypedParametersWithInitializers4.ts, 1, 11)) | ||
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) | ||
>ctx : Symbol(ctx, Decl(contextuallyTypedParametersWithInitializers4.ts, 2, 35)) | ||
>TContext : Symbol(TContext, Decl(contextuallyTypedParametersWithInitializers4.ts, 0, 22)) | ||
>args : Symbol(args, Decl(contextuallyTypedParametersWithInitializers4.ts, 2, 49)) | ||
|
||
>(context: TContext, methods: TMethods): void; | ||
>context : Symbol(context, Decl(contextuallyTypedParametersWithInitializers4.ts, 3, 2)) | ||
>TContext : Symbol(TContext, Decl(contextuallyTypedParametersWithInitializers4.ts, 0, 22)) | ||
>methods : Symbol(methods, Decl(contextuallyTypedParametersWithInitializers4.ts, 3, 20)) | ||
>TMethods : Symbol(TMethods, Decl(contextuallyTypedParametersWithInitializers4.ts, 1, 11)) | ||
|
||
test( | ||
>test : Symbol(test, Decl(contextuallyTypedParametersWithInitializers4.ts, 0, 0)) | ||
{ | ||
count: 0, | ||
>count : Symbol(count, Decl(contextuallyTypedParametersWithInitializers4.ts, 6, 3)) | ||
|
||
}, | ||
{ | ||
checkLimit: (ctx, max = 3) => {}, | ||
>checkLimit : Symbol(checkLimit, Decl(contextuallyTypedParametersWithInitializers4.ts, 9, 3)) | ||
>ctx : Symbol(ctx, Decl(contextuallyTypedParametersWithInitializers4.ts, 10, 17)) | ||
>max : Symbol(max, Decl(contextuallyTypedParametersWithInitializers4.ts, 10, 21)) | ||
|
||
}, | ||
); | ||
|
39 changes: 39 additions & 0 deletions
39
tests/baselines/reference/contextuallyTypedParametersWithInitializers4.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
//// [tests/cases/compiler/contextuallyTypedParametersWithInitializers4.ts] //// | ||
|
||
=== contextuallyTypedParametersWithInitializers4.ts === | ||
declare function test< | ||
>test : <TContext, TMethods extends Record<string, (ctx: TContext, ...args: (1 | 2)[]) => unknown>>(context: TContext, methods: TMethods) => void | ||
|
||
TContext, | ||
TMethods extends Record<string, (ctx: TContext, ...args: (1 | 2)[]) => unknown>, | ||
>ctx : TContext | ||
>args : (1 | 2)[] | ||
|
||
>(context: TContext, methods: TMethods): void; | ||
>context : TContext | ||
>methods : TMethods | ||
|
||
test( | ||
>test( { count: 0, }, { checkLimit: (ctx, max = 3) => {}, },) : void | ||
>test : <TContext, TMethods extends Record<string, (ctx: TContext, ...args: (1 | 2)[]) => unknown>>(context: TContext, methods: TMethods) => void | ||
{ | ||
>{ count: 0, } : { count: number; } | ||
|
||
count: 0, | ||
>count : number | ||
>0 : 0 | ||
|
||
}, | ||
{ | ||
>{ checkLimit: (ctx, max = 3) => {}, } : { checkLimit: (ctx: { count: number; }, max?: number) => void; } | ||
|
||
checkLimit: (ctx, max = 3) => {}, | ||
>checkLimit : (ctx: { count: number; }, max?: number) => void | ||
>(ctx, max = 3) => {} : (ctx: { count: number; }, max?: number) => void | ||
>ctx : { count: number; } | ||
>max : number | ||
>3 : 3 | ||
|
||
}, | ||
); | ||
|
File renamed without changes.
22 changes: 22 additions & 0 deletions
22
tests/cases/compiler/contextuallyTypedParametersWithInitializers2.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// @strict: true | ||
// @noEmit: true | ||
|
||
declare function test1< | ||
TContext, | ||
TMethods extends Record<string, (ctx: TContext, ...args: never[]) => unknown>, | ||
>(context: TContext, methods: TMethods): void; | ||
|
||
test1( | ||
{ | ||
count: 0, | ||
}, | ||
{ | ||
checkLimit: (ctx, max = 500) => {}, | ||
hasAccess: (ctx, user: { name: string }) => {}, | ||
}, | ||
); | ||
|
||
declare const num: number; | ||
const test2: (arg: 1 | 2) => void = (arg = num) => {}; | ||
|
||
const test3: (arg: number) => void = (arg = 1) => {}; |
18 changes: 18 additions & 0 deletions
18
tests/cases/compiler/contextuallyTypedParametersWithInitializers3.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// @strict: true | ||
// @noEmit: true | ||
|
||
type CanvasDirection = "RIGHT" | "LEFT"; | ||
|
||
interface GraphActions { | ||
setDirection: (direction: CanvasDirection) => void; | ||
} | ||
|
||
export declare function create<T>(config: T): void; | ||
|
||
declare function takesDirection(direction: CanvasDirection): void; | ||
|
||
create<GraphActions>({ | ||
setDirection: (direction = "RIGHT") => { | ||
takesDirection(direction); | ||
}, | ||
}); |
Oops, something went wrong.