-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Misleading error message when generic type alias is illegally circular #33868
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
This is working as intended. The alias
The error message Type 'Primitive' is not generic. is a consequence of the first error, but perhaps it's abit misleading. |
You can read here for the latest spec on recrusive references: #33050. |
What would be the proposed fix here? Removing the error message completely, or updating it to something like: |
The flip side is also strange: type Z<T> = Z;
// ~ ! <-- no error here
// ^-- Type alias 'Z' circularly references itself. My (possibly naive) expectation here is that |
Well, two implementation codes are essentially same. Two codes are all using the Really it's the intended spec? not bug? Error Codetype Primitive<Instance> = value_of<Instance> extends object
? Instance extends IJsonable<infer Raw>
? Primitive<Raw>
: PrimitiveObject<Instance>
: value_of<Instance>;
type PrimitiveObject<Instance> =
{
[P in keyof Instance]: Instance[P] extends Function
? never
: Primitive<Instance[P]>
}; Detour Codetype Primitive<Instance> = value_of<Instance> extends object
? Instance extends IJsonable<infer Raw>
? Raw extends object
? PrimitiveObject<Raw>
: value_of<Raw>
: PrimitiveObject<Instance>
: value_of<Instance>; |
No longer an error as of 5.3 |
Summary
A generic type says "I'm not a generic type".
Code occuring the bug
I tried to make a generic type converting to be primitive for the JSON message. The type
Primitive
would convert an object type to be primitive. All methods defined in the object type (class) would be erased. If the class has atoJSON()
method,Primitive
would select its return type.The above is my implementation code in my first try. However, a compile error has occured:
Detour method, but...
To avoid the bug, I wrote another implementation code for the
IJsonable<Raw>
. However, I think it's a typical vulnerable and duplicated implementation. I hope the bug to be fixed.The text was updated successfully, but these errors were encountered: