-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
change default ThunkArg of cAT to OptionalUnknown #814
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
Conversation
So the only issue here is TS compat with That doesn't seem like it's worth us spending much effort on, tbh - I'd rather have better types in TS files. |
Might be affecting JS typehints in VSCode in general as well. My testing on that has been a little unconclusive. |
I'm just really hesitant to do any changes that weaken the actual TS support for the purposes of semi-typed-JS interop :) |
Okay, blank CRA JS seems unaffected. |
Since TypeScript 4.0, the following example will cause an error when checking JavaScript files (with allowJs & checkJs): ```js const thunk = createAsyncThunk('', arg => {}) thunk() // @ts-expect-error Expected 0 arguments, but got 1.ts(2554) thunk('something') ``` The only way around that without breaking too much explicit existing behaviour is this type "OptionalUnknown". On the flip side, using a payloadcreator without a defined argument, like ```ts const thunk = createAsyncThunk('', () => {}) ``` will now generate a thunk that can optionally be called with any first argument opposed to a thunk that would not accept any argument before.
305928e
to
6753973
Compare
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 6753973:
|
Just some more experimentation:
{
"compilerOptions": {
"moduleResolution": "node",
"target": "es6",
"checkJs": true
}
} to the project. This can be fixed in the code by providing a type for the argument via const thunk2 = createAsyncThunk(
"",
/** @param arg {string} */
(arg) => {
console.log(arg);
}
);
// @ts-expect-error Expected 1 arguments, but got 0.ts(2554)
thunk2();
thunk2("something"); Especially the So we could alternatively go the way of documenting this. But I wouldn't really know where to put this. |
This also goes for #680, which we can't really fix in types. We also cannot detect if the current file is being run in TS or JS and act accordingly. |
I'm still not really clear on what the status of this one is :) |
Could be cool, could be uncool, not really sure how many people it would affect. |
Since TypeScript 4.0, the following example will cause an error when checking JavaScript files (with allowJs & checkJs):
The only way around that without breaking too much explicit existing behaviour is this type "OptionalUnknown".
On the flip side, using a payloadcreator without a defined argument, like
will now generate a thunk that can optionally be called with any first argument opposed to a thunk that would not accept any argument before.
This is not nice, but there's not much way around it without significantly changing
createAsyncThunk
types that are public. (And even then I'm not sure if I could find a better solution).This is a change as well, but only one that will lead to more relaxed typechecking, so nobody upgrading should get any errors.
@markerikson, opinions on this?