-
Notifications
You must be signed in to change notification settings - Fork 12.8k
[typeBaselines] Recursive type gets erased to any immediately #523
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
Comments
I'm not sure by what logic you would expect the resulting type to be |
What about: var b: () => {next: typeof b; data: number}; It seems to me that neither 'any' or '()=>any' is what the developer intended. I'm also wondering how this interacts with the recursive type literal proposal (#517). Using the typeof b like the above just makes me think it's a poor man's version of the recursive type literal. |
Let me clarify. My understanding of the current state of things is the following:
var a: { x: typeof a}; has a recursive type, but var a: () => typeof a;
var b: { (): typeof b; }; do not. The present bug is addressing number 2 above. We should be consistent no matter how the type references the variable. Right now, the laziness in |
I think you're right, we shouldn't eagerly resolve a return type annotation in |
Great! While we're at it, are there any other positions inside a type that need to be deferred like this to allow for recursive types? Indexers definitely. What about type parameter constraints in a signature? Type arguments in a type reference? We can test these to see if they behave correctly. |
Indexer types are already deferred. Ditto type parameter constraints. Type arguments in a type reference are not deferred--we deeply rely on the notion that a the identity of a type reference is computed from the identity of the generic type and the identity of each of the type arguments. So, |
Hmm, that is unfortunate about the type arguments, particularly because we want the instantiation to just be a substitution of type arguments for type parameters. It should be synonymous with the expanded form. Indexer types don't look deferred to me. getTypeFromTypeLiteralNode calls getIndexTypeOfSymbol, which calls getTypeFromTypeNode. So I think they have the same problem as call/construct signatures. |
I just realized that |
Now that you mention it, yes, that seems like the most general solution. |
Test case: tests/cases/compiler/declFileTypeofFunction.ts
var b: () => typeof b;
We expect both of these to be
() => any
The text was updated successfully, but these errors were encountered: