8000 Enable `strictFunctionTypes` by liuxingbaoyu · Pull Request #17492 · babel/babel · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@liuxingbaoyu
Copy link
Member
@liuxingbaoyu liuxingbaoyu commented Aug 27, 2025
Q                       A
Fixed Issues? Fixes #1, Fixes #2
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

I 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.

Comment on lines +406 to 410
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;
}
Copy link
Member Author

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.

@babel-bot
Copy link
Collaborator

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/59872

Comment on lines +66 to +69
[k: `${string}|${string}`]: VisitNode<
S,
IsStrictFunctionTypesEnabled extends true ? any : t.Node
>;
Copy link
Member Author

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.

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.

@liuxingbaoyu
Copy link
Member Author

Currently, the upstream gensync type needs to be modified. It would be great if there is another way!
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/9da85b1e3a1cf4bac4cc1ad98fd81e7f00c7178e/types/gensync/index.d.ts#L10
declare function gensync<A extends unknown[], R, E = unknown>(
to
declare function gensync<A extends unknown[], R, E = any>(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
0