-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Allow non-generic return types to be read from single generic call signatures #54477
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
sandersn
merged 5 commits into
microsoft:main
from
Andarist:non-generic-return-types-avoid-circularity
Nov 29, 2023
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
be49d9c
Allow non-generic return types to be read from single generic call si…
Andarist 3b17f59
Merge remote-tracking branch 'origin/main' into non-generic-return-ty…
Andarist 65cfba0
Merge branch 'main' into non-generic-return-types-avoid-circularity
sandersn 29e514c
Merge branch 'main' into non-generic-return-types-avoid-circularity
sandersn b781d58
Add missed baseline update
sandersn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
41 changes: 41 additions & 0 deletions
41
tests/baselines/reference/circularReferenceInReturnType.symbols
This file contains hidden or 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,41 @@ | ||
//// [tests/cases/compiler/circularReferenceInReturnType.ts] //// | ||
|
||
=== circularReferenceInReturnType.ts === | ||
declare function fn1<T>(cb: () => T): string; | ||
>fn1 : Symbol(fn1, Decl(circularReferenceInReturnType.ts, 0, 0)) | ||
>T : Symbol(T, Decl(circularReferenceInReturnType.ts, 0, 21)) | ||
>cb : Symbol(cb, Decl(circularReferenceInReturnType.ts, 0, 24)) | ||
>T : Symbol(T, Decl(circularReferenceInReturnType.ts, 0, 21)) | ||
|
||
const res1 = fn1(() => res1); | ||
>res1 : Symbol(res1, Decl(circularReferenceInReturnType.ts, 1, 5)) | ||
>fn1 : Symbol(fn1, Decl(circularReferenceInReturnType.ts, 0, 0)) | ||
>res1 : Symbol(res1, Decl(circularReferenceInReturnType.ts, 1, 5)) | ||
|
||
declare function fn2<T>(): (cb: () => any) => (a: T) => void; | ||
>fn2 : Symbol(fn2, Decl(circularReferenceInReturnType.ts, 1, 29)) | ||
>T : Symbol(T, Decl(circularReferenceInReturnType.ts, 3, 21)) | ||
>cb : Symbol(cb, Decl(circularReferenceInReturnType.ts, 3, 28)) | ||
>a : Symbol(a, Decl(circularReferenceInReturnType.ts, 3, 47)) | ||
>T : Symbol(T, Decl(circularReferenceInReturnType.ts, 3, 21)) | ||
|
||
const res2 = fn2()(() => res2); | ||
>res2 : Symbol(res2, Decl(circularReferenceInReturnType.ts, 4, 5)) | ||
>fn2 : Symbol(fn2, Decl(circularReferenceInReturnType.ts, 1, 29)) | ||
>res2 : Symbol(res2, Decl(circularReferenceInReturnType.ts, 4, 5)) | ||
|
||
declare function fn3<T>(): <T2>(cb: (arg: T2) => any) => (a: T) => void; | ||
>fn3 : Symbol(fn3, Decl(circularReferenceInReturnType.ts, 4, 31)) | ||
>T : Symbol(T, Decl(circularReferenceInReturnType.ts, 6, 21)) | ||
>T2 : Symbol(T2, Decl(circularReferenceInReturnType.ts, 6, 28)) | ||
>cb : Symbol(cb, Decl(circularReferenceInReturnType.ts, 6, 32)) | ||
>arg : Symbol(arg, Decl(circularReferenceInReturnType.ts, 6, 37)) | ||
>T2 : Symbol(T2, Decl(circularReferenceInReturnType.ts, 6, 28)) | ||
>a : Symbol(a, Decl(circularReferenceInReturnType.ts, 6, 58)) | ||
>T : Symbol(T, Decl(circularReferenceInReturnType.ts, 6, 21)) | ||
|
||
const res3 = fn3()(() => res3); | ||
>res3 : Symbol(res3, Decl(circularReferenceInReturnType.ts, 7, 5)) | ||
>fn3 : Symbol(fn3, Decl(circularReferenceInReturnType.ts, 4, 31)) | ||
>res3 : Symbol(res3, Decl(circularReferenceInReturnType.ts, 7, 5)) | ||
|
41 changes: 41 additions & 0 deletions
41
tests/baselines/reference/circularReferenceInReturnType.types
This file contains hidden or 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,41 @@ | ||
//// [tests/cases/compiler/circularReferenceInReturnType.ts] //// | ||
|
||
=== circularReferenceInReturnType.ts === | ||
declare function fn1<T>(cb: () => T): string; | ||
>fn1 : <T>(cb: () => T) => string | ||
>cb : () => T | ||
|
||
const res1 = fn1(() => res1); | ||
>res1 : string | ||
>fn1(() => res1) : string | ||
>fn1 : <T>(cb: () => T) => string | ||
>() => res1 : () => string | ||
>res1 : string | ||
|
||
declare function fn2<T>(): (cb: () => any) => (a: T) => void; | ||
>fn2 : <T>() => (cb: () => any) => (a: T) => void | ||
>cb : () => any | ||
>a : T | ||
|
||
const res2 = fn2()(() => res2); | ||
>res2 : (a: unknown) => void | ||
>fn2()(() => res2) : (a: unknown) => void | ||
>fn2() : (cb: () => any) => (a: unknown) => void | ||
>fn2 : <T>() => (cb: () => any) => (a: T) => void | ||
>() => res2 : () => (a: unknown) => void | ||
>res2 : (a: unknown) => void | ||
|
||
declare function fn3<T>(): <T2>(cb: (arg: T2) => any) => (a: T) => void; | ||
>fn3 : <T>() => <T2>(cb: (arg: T2) => any) => (a: T) => void | ||
>cb : (arg: T2) => any | ||
>arg : T2 | ||
>a : T | ||
|
||
const res3 = fn3()(() => res3); | ||
>res3 : (a: unknown) => void | ||
>fn3()(() => res3) : (a: unknown) => void | ||
>fn3() : <T2>(cb: (arg: T2) => any) => (a: unknown) => void | ||
>fn3 : <T>() => <T2>(cb: (arg: T2) => any) => (a: T) => void | ||
>() => res3 : () => (a: unknown) => void | ||
>res3 : (a: unknown) => void | ||
|
160 changes: 160 additions & 0 deletions
160
tests/baselines/reference/circularReferenceInReturnType2.symbols
This file contains hidden or 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,160 @@ | ||
//// [tests/cases/compiler/circularReferenceInReturnType2.ts] //// | ||
|
||
=== circularReferenceInReturnType2.ts === | ||
type ObjectType<Source> = { | ||
>ObjectType : Symbol(ObjectType, Decl(circularReferenceInReturnType2.ts, 0, 0)) | ||
>Source : Symbol(Source, Decl(circularReferenceInReturnType2.ts, 0, 16)) | ||
|
||
kind: "object"; | ||
>kind : Symbol(kind, Decl(circularReferenceInReturnType2.ts, 0, 27)) | ||
|
||
__source: (source: Source) => void; | ||
>__source : Symbol(__source, Decl(circularReferenceInReturnType2.ts, 1, 17)) | ||
>source : Symbol(source, Decl(circularReferenceInReturnType2.ts, 2, 13)) | ||
>Source : Symbol(Source, Decl(circularReferenceInReturnType2.ts, 0, 16)) | ||
|
||
}; | ||
|
||
type Field<Source, Key extends string> = { | ||
>Field : Symbol(Field, Decl(circularReferenceInReturnType2.ts, 3, 2)) | ||
>Source : Symbol(Source, Decl(circularReferenceInReturnType2.ts, 5, 11)) | ||
>Key : Symbol(Key, Decl(circularReferenceInReturnType2.ts, 5, 18)) | ||
|
||
__key: (key: Key) => void; | ||
>__key : Symbol(__key, Decl(circularReferenceInReturnType2.ts, 5, 42)) | ||
>key : Symbol(key, Decl(circularReferenceInReturnType2.ts, 6, 10)) | ||
>Key : Symbol(Key, Decl(circularReferenceInReturnType2.ts, 5, 18)) | ||
|
||
__source: (source: Source) => void; | ||
>__source : Symbol(__source, Decl(circularReferenceInReturnType2.ts, 6, 28)) | ||
>source : Symbol(source, Decl(circularReferenceInReturnType2.ts, 7, 13)) | ||
>Source : Symbol(Source, Decl(circularReferenceInReturnType2.ts, 5, 11)) | ||
|
||
}; | ||
|
||
declare const object: <Source>() => < | ||
>object : Symbol(object, Decl(circularReferenceInReturnType2.ts, 10, 13)) | ||
>Source : Symbol(Source, Decl(circularReferenceInReturnType2.ts, 10, 23)) | ||
|
||
Fields extends { | ||
>Fields : Symbol(Fields, Decl(circularReferenceInReturnType2.ts, 10, 37)) | ||
|
||
[Key in keyof Fields]: Field<Source, Key & string>; | ||
>Key : Symbol(Key, Decl(circularReferenceInReturnType2.ts, 12, 5)) | ||
>Fields : Symbol(Fields, Decl(circularReferenceInReturnType2.ts, 10, 37)) | ||
>Field : Symbol(Field, Decl(circularReferenceInReturnType2.ts, 3, 2)) | ||
>Source : Symbol(Source, Decl(circularReferenceInReturnType2.ts, 10, 23)) | ||
>Key : Symbol(Key, Decl(circularReferenceInReturnType2.ts, 12, 5)) | ||
} | ||
>(config: { | ||
>config : Symbol(config, Decl(circularReferenceInReturnType2.ts, 14, 2)) | ||
|
||
name: string; | ||
>name : Symbol(name, Decl(circularReferenceInReturnType2.ts, 14, 11)) | ||
|
||
fields: Fields | (() => Fields); | ||
>fields : Symbol(fields, Decl(circularReferenceInReturnType2.ts, 15, 15)) | ||
>Fields : Symbol(Fields, Decl(circularReferenceInReturnType2.ts, 10, 37)) | ||
>Fields : Symbol(Fields, Decl(circularReferenceInReturnType2.ts, 10, 37)) | ||
|
||
}) => ObjectType<Source>; | ||
>ObjectType : Symbol(ObjectType, Decl(circularReferenceInReturnType2.ts, 0, 0)) | ||
>Source : Symbol(Source, Decl(circularReferenceInReturnType2.ts, 10, 23)) | ||
|
||
type InferValueFromObjectType<Type extends ObjectType<any>> = | ||
>InferValueFromObjectType : Symbol(InferValueFromObjectType, Decl(circularReferenceInReturnType2.ts, 17, 25)) | ||
>Type : Symbol(Type, Decl(circularReferenceInReturnType2.ts, 19, 30)) | ||
>ObjectType : Symbol(ObjectType, Decl(circularReferenceInReturnType2.ts, 0, 0)) | ||
|
||
Type extends ObjectType<infer Source> ? Source : never; | ||
>Type : Symbol(Type, Decl(circularReferenceInReturnType2.ts, 19, 30)) | ||
>ObjectType : Symbol(ObjectType, Decl(circularReferenceInReturnType2.ts, 0, 0)) | ||
>Source : Symbol(Source, Decl(circularReferenceInReturnType2.ts, 20, 31)) | ||
>Source : Symbol(Source, Decl(circularReferenceInReturnType2.ts, 20, 31)) | ||
|
||
type FieldResolver<Source, TType extends ObjectType<any>> = ( | ||
>FieldResolver : Symbol(FieldResolver, Decl(circularReferenceInReturnType2.ts, 20, 57)) | ||
>Source : Symbol(Source, Decl(circularReferenceInReturnType2.ts, 22, 19)) | ||
>TType : Symbol(TType, Decl(circularReferenceInReturnType2.ts, 22, 26)) | ||
>ObjectType : Symbol(ObjectType, Decl(circularReferenceInReturnType2.ts, 0, 0)) | ||
|
||
source: Source | ||
>source : Symbol(source, Decl(circularReferenceInReturnType2.ts, 22, 61)) | ||
>Source : Symbol(Source, Decl(circularReferenceInReturnType2.ts, 22, 19)) | ||
|
||
) => InferValueFromObjectType<TType>; | ||
>InferValueFromObjectType : Symbol(InferValueFromObjectType, Decl(circularReferenceInReturnType2.ts, 17, 25)) | ||
>TType : Symbol(TType, Decl(circularReferenceInReturnType2.ts, 22, 26)) | ||
|
||
type FieldFuncArgs<Source, Type extends ObjectType<any>> = { | ||
>FieldFuncArgs : Symbol(FieldFuncArgs, Decl(circularReferenceInReturnType2.ts, 24, 37)) | ||
>Source : Symbol(Source, Decl(circularReferenceInReturnType2.ts, 26, 19)) | ||
>Type : Symbol(Type, Decl(circularReferenceInReturnType2.ts, 26, 26)) | ||
>ObjectType : Symbol(ObjectType, Decl(circularReferenceInReturnType2.ts, 0, 0)) | ||
|
||
type: Type; | ||
>type : Symbol(type, Decl(circularReferenceInReturnType2.ts, 26, 60)) | ||
>Type : Symbol(Type, Decl(circularReferenceInReturnType2.ts, 26, 26)) | ||
|
||
resolve: FieldResolver<Source, Type>; | ||
>resolve : Symbol(resolve, Decl(circularReferenceInReturnType2.ts, 27, 13)) | ||
>FieldResolver : Symbol(FieldResolver, Decl(circularReferenceInReturnType2.ts, 20, 57)) | ||
>Source : Symbol(Source, Decl(circularReferenceInReturnType2.ts, 26, 19)) | ||
>Type : Symbol(Type, Decl(circularReferenceInReturnType2.ts, 26, 26)) | ||
|
||
}; | ||
|
||
declare const field: <Source, Type extends ObjectType<any>, Key extends string>( | ||
>field : Symbol(field, Decl(circularReferenceInReturnType2.ts, 31, 13)) | ||
>Source : Symbol(Source, Decl(circularReferenceInReturnType2.ts, 31, 22)) | ||
>Type : Symbol(Type, Decl(circularReferenceInReturnType2.ts, 31, 29)) | ||
>ObjectType : Symbol(ObjectType, Decl(circularReferenceInReturnType2.ts, 0, 0)) | ||
>Key : Symbol(Key, Decl(circularReferenceInReturnType2.ts, 31, 59)) | ||
|
||
field: FieldFuncArgs<Source, Type> | ||
>field : Symbol(field, Decl(circularReferenceInReturnType2.ts, 31, 80)) | ||
>FieldFuncArgs : Symbol(FieldFuncArgs, Decl(circularReferenceInReturnType2.ts, 24, 37)) | ||
>Source : Symbol(Source, Decl(circularReferenceInReturnType2.ts, 31, 22)) | ||
>Type : Symbol(Type, Decl(circularReferenceInReturnType2.ts, 31, 29)) | ||
|
||
) => Field<Source, Key>; | ||
>Field : Symbol(Field, Decl(circularReferenceInReturnType2.ts, 3, 2)) | ||
>Source : Symbol(Source, Decl(circularReferenceInReturnType2.ts, 31, 22)) | ||
>Key : Symbol(Key, Decl(circularReferenceInReturnType2.ts, 31, 59)) | ||
|
||
type Something = { foo: number }; | ||
>Something : Symbol(Something, Decl(circularReferenceInReturnType2.ts, 33, 24)) | ||
>foo : Symbol(foo, Decl(circularReferenceInReturnType2.ts, 35, 18)) | ||
|
||
const A = object<Something>()({ | ||
>A : Symbol(A, Decl(circularReferenceInReturnType2.ts, 37, 5)) | ||
>object : Symbol(object, Decl(circularReferenceInReturnType2.ts, 10, 13)) | ||
>Something : Symbol(Something, Decl(circularReferenceInReturnType2.ts, 33, 24)) | ||
|
||
name: "A", | ||
>name : Symbol(name, Decl(circularReferenceInReturnType2.ts, 37, 31)) | ||
|
||
fields: () => ({ | ||
>fields : Symbol(fields, Decl(circularReferenceInReturnType2.ts, 38, 12)) | ||
|
||
a: field({ | ||
>a : Symbol(a, Decl(circularReferenceInReturnType2.ts, 39, 18)) | ||
>field : Symbol(field, Decl(circularReferenceInReturnType2.ts, 31, 13)) | ||
|
||
type: A, | ||
>type : Symbol(type, Decl(circularReferenceInReturnType2.ts, 40, 14)) | ||
>A : Symbol(A, Decl(circularReferenceInReturnType2.ts, 37, 5)) | ||
|
||
resolve() { | ||
>resolve : Symbol(resolve, Decl(circularReferenceInReturnType2.ts, 41, 14)) | ||
|
||
return { | ||
foo: 100, | ||
>foo : Symbol(foo, Decl(circularReferenceInReturnType2.ts, 43, 16)) | ||
|
||
}; | ||
}, | ||
}), | ||
}), | ||
}); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.