-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Revert #54477 but keep the tests #57160
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
DanielRosenwasser
merged 1 commit into
microsoft:main
from
sandersn:revert-54477-but-keep-tests
Jan 25, 2024
Merged
Changes from all commits
Commits
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
19 changes: 19 additions & 0 deletions
19
tests/baselines/reference/circularReferenceInReturnType.errors.txt
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a minimal repro for the break, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes |
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,19 @@ | ||
circularReferenceInReturnType.ts(3,7): error TS7022: 'res1' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. | ||
circularReferenceInReturnType.ts(9,7): error TS7022: 'res3' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. | ||
|
||
|
||
==== circularReferenceInReturnType.ts (2 errors) ==== | ||
// inference fails for res1 and res2, but ideally should not | ||
declare function fn1<T>(cb: () => T): string; | ||
const res1 = fn1(() => res1); | ||
~~~~ | ||
!!! error TS7022: 'res1' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. | ||
|
||
declare function fn2<T>(): (cb: () => any) => (a: T) => void; | ||
const res2 = fn2()(() => res2); | ||
|
||
declare function fn3<T>(): <T2>(cb: (arg: T2) => any) => (a: T) => void; | ||
const res3 = fn3()(() => res3); | ||
~~~~ | ||
!!! error TS7022: 'res3' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. | ||
|
49 changes: 25 additions & 24 deletions
49
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 |
---|---|---|
@@ -1,41 +1,42 @@ | ||
//// [tests/cases/compiler/circularReferenceInReturnType.ts] //// | ||
|
||
=== circularReferenceInReturnType.ts === | ||
// inference fails for res1 and res2, but ideally should not | ||
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)) | ||
>T : Symbol(T, Decl(circularReferenceInReturnType.ts, 1, 21)) | ||
>cb : Symbol(cb, Decl(circularReferenceInReturnType.ts, 1, 24)) | ||
>T : Symbol(T, Decl(circularReferenceInReturnType.ts, 1, 21)) | ||
|
||
const res1 = fn1(() => res1); | ||
>res1 : Symbol(res1, Decl(circularReferenceInReturnType.ts, 1, 5)) | ||
>res1 : Symbol(res1, Decl(circularReferenceInReturnType.ts, 2, 5)) | ||
>fn1 : Symbol(fn1, Decl(circularReferenceInReturnType.ts, 0, 0)) | ||
>res1 : Symbol(res1, Decl(circularReferenceInReturnType.ts, 1, 5)) | ||
>res1 : Symbol(res1, Decl(circularReferenceInReturnType.ts, 2, 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)) | ||
>fn2 : Symbol(fn2, Decl(circularReferenceInReturnType.ts, 2, 29)) | ||
>T : Symbol(T, Decl(circularReferenceInReturnType.ts, 4, 21)) | ||
>cb : Symbol(cb, Decl(circularReferenceInReturnType.ts, 4, 28)) | ||
>a : Symbol(a, Decl(circularReferenceInReturnType.ts, 4, 47)) | ||
>T : Symbol(T, Decl(circularReferenceInReturnType.ts, 4, 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)) | ||
>res2 : Symbol(res2, Decl(circularReferenceInReturnType.ts, 5, 5)) | ||
>fn2 : Symbol(fn2, Decl(circularReferenceInReturnType.ts, 2, 29)) | ||
>res2 : Symbol(res2, Decl(circularReferenceInReturnType.ts, 5, 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)) | ||
>fn3 : Symbol(fn3, Decl(circularReferenceInReturnType.ts, 5, 31)) | ||
>T : Symbol(T, Decl(circularReferenceInReturnType.ts, 7, 21)) | ||
>T2 : Symbol(T2, Decl(circularReferenceInReturnType.ts, 7, 28)) | ||
>cb : Symbol(cb, Decl(circularReferenceInReturnType.ts, 7, 32)) | ||
>arg : Symbol(arg, Decl(circularReferenceInReturnType.ts, 7, 37)) | ||
>T2 : Symbol(T2, Decl(circularReferenceInReturnType.ts, 7, 28)) | ||
>a : Symbol(a, Decl(circularReferenceInReturnType.ts, 7, 58)) | ||
>T : Symbol(T, Decl(circularReferenceInReturnType.ts, 7, 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)) | ||
>res3 : Symbol(res3, Decl(circularReferenceInReturnType.ts, 8, 5)) | ||
>fn3 : Symbol(fn3, Decl(circularReferenceInReturnType.ts, 5, 31)) | ||
>res3 : Symbol(res3, Decl(circularReferenceInReturnType.ts, 8, 5)) | ||
|
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
58 changes: 58 additions & 0 deletions
58
tests/baselines/reference/circularReferenceInReturnType2.errors.txt
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,58 @@ | ||
circularReferenceInReturnType2.ts(39,7): error TS7022: 'A' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. | ||
|
||
|
||
==== circularReferenceInReturnType2.ts (1 errors) ==== | ||
type ObjectType<Source> = { | ||
kind: "object"; | ||
__source: (source: Source) => void; | ||
}; | ||
|
||
type Field<Source, Key extends string> = { | ||
__key: (key: Key) => void; | ||
__source: (source: Source) => void; | ||
}; | ||
|
||
declare const object: <Source>() => < | ||
Fields extends { | ||
[Key in keyof Fields]: Field<Source, Key & string>; | ||
} | ||
>(config: { | ||
name: string; | ||
fields: Fields | (() => Fields); | ||
}) => ObjectType<Source>; | ||
|
||
type InferValueFromObjectType<Type extends ObjectType<any>> = | ||
Type extends ObjectType<infer Source> ? Source : never; | ||
|
||
type FieldResolver<Source, TType extends ObjectType<any>> = ( | ||
source: Source | ||
) => InferValueFromObjectType<TType>; | ||
|
||
type FieldFuncArgs<Source, Type extends ObjectType<any>> = { | ||
type: Type; | ||
resolve: FieldResolver<Source, Type>; | ||
}; | ||
|
||
declare const field: <Source, Type extends ObjectType<any>, Key extends string>( | ||
field: FieldFuncArgs<Source, Type> | ||
) => Field<Source, Key>; | ||
|
||
type Something = { foo: number }; | ||
|
||
// inference fails here, but ideally should not | ||
const A = object<Something>()({ | ||
~ | ||
!!! error TS7022: 'A' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. | ||
name: "A", | ||
fields: () => ({ | ||
a: field({ | ||
type: A, | ||
resolve() { | ||
return { | ||
foo: 100, | ||
}; | ||
}, | ||
}), | ||
}), | ||
}); | ||
|
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I try to understand how to use
couldContainTypeVariables
appropriately and I wonder how this was different from howcheckFunctionExpressionOrObjectLiteralMethod
uses it here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see how this is part of the inference algorithm and the check here was kinda not - but I still fail to understand how those 2 situations are fundamentally different so it's OK to call it within one context and not OK to call it within another.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that other use is correct either...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also tried to repro the regression caused by this cause I wanted to add a test case for it but I failed. It has been mentioned that it was only visible in the IDE but I assume that this particular report was reported by a bot reporting
tsc
-related changes. I couldn't repro with either though.