-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
"type MyType = MyType" should not be allowed #5771
Comments
Still an issue in v0.67.0 |
Still an issue in v0.70.0 |
This is not really a bug, I would say that it works as expected. |
So you're saying this is valid? Bear in mind that |
Yes, this is allowed because recursive types are allowed. |
I agree, yet IMO we should still complain about recursive types which doesn't have a base case like OCaml does |
This is now banned |
So I came across this one because the field
DatabaseRow.dumping_ground
is inspired by a postgres nullable JSONB field that could contain anything, if defined. Unfortunately we have the following in our .flowconfig so I can't useany | null
;So instead of doing
// $FlowFixMe
everywhere I wanted to doany
for JSON, I decided to encapsulate it astype JsonField = any;
, so that I could put the// $FlowFixMe
in one place. I then did a find-replace onany
in the file (by accident turning the above declaration intotype JsonField = JsonField
, and much to my surprise Flow then told me that my// $FlowFixMe
wasn't needed! I took it away and saw that indeed Flow does not complain abouttype JsonField = JsonField;
So thanks for sorting my dilemma cause this bug means I don't have to spend any time trying to find out how else to specify
any
because our linting doesn't allow it.However, it is a bug and should probably be fixed. Copying/pasting the above code into the TypeScript playground gives an error saying that the type JsonField is a circular reference.
Keep in mind that circular type references are not always bad. For example the following is a perfectly valid example of the usefulness of circular type references. You could define a dynamic JSON import as JSONValue using the code below, and then do useful type-narrowing on it to get useful errors etc.
The 4 lines of code at the top that define the types would fail if pasted into the TypeScript playground as-is because it's detected as a circular type reference (microsoft/TypeScript#14174). But this check can be bypassed in TS using the following code:
Interestingly, doing that in Flow causes the Array type checking to completely break down, which I'll raise separately.
The text was updated successfully, but these errors were encountered: