-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Enable strictFunctionTypes
#17492
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
base: main
Are you sure you want to change the base?
Enable strictFunctionTypes
#17492
Conversation
| function autoInherits<Fn extends Function>(fn: Fn): Fn { | ||
| return function (this: any, member: any) { | ||
| return t.inherits(fn.apply(this, arguments as any), member.node); | ||
| } as Fn; | ||
| } as unknown as Fn; | ||
| } |
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 don't know why the original code doesn't work here.
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/59872 |
| [k: `${string}|${string}`]: VisitNode< | ||
| S, | ||
| IsStrictFunctionTypesEnabled extends true ? any : t.Node | ||
| >; |
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 have tried many things but still can't solve the problem from the root.
TS doesn't seem to support generating values based on mapped keys.
If we pre-generate all possible combinations, they will exceed TS's limits.
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 don't think it's possible to strongly type visitors with keys like this without something like a createVisitor helper function, since the types are self-referential - the value types must be inferred from the keys used by the caller (since defining all combinations up front isn't possible). Adding something like that might be nice anyway, but I guess it wouldn't help older callers.
|
Currently, the upstream |
Fixes #1, Fixes #2I think this PR is not good enough, suggestions are welcome!
This PR had its pros and cons: it helped us find some type errors, but it also made some operations more cumbersome.
However, it seems acceptable, as it reflects the situation faced by users.