-
Notifications
You must be signed in to change notification settings - Fork 12.8k
TypeScript augmentation challenge #9015
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
So i am not familiar with redux to know if the issue is in the usage or the declaration. The module augmentation seems to work fine for me using your project i am not sure i understand what is the issue. A note for future issue reporting, a git repo is much better way to share the state than a gist. |
@mhegazy The problem is that if you put the module augmentation in a separate file then it hides the module definition in node_modules/redux. @garthk The only way I have found to get it working is to move redux's index.d.ts out of node_modules and wrap it's contents with
Then module augmentations work as expected. I don't know enough about TypeScript to know why this behaves differently to using the typings distributed with redux, or how to solve it in a better way. What I have is an npm postinstall script that does all this, and as unsatisfactory as it is, it is the only way I have found that works. If you or anyone else finds a better way, please let me know! |
The file needs to be a module. just like i did. so something like this should work: /// myAugmentationFile.ts
import * as redux from "redux";
declare module "redux" {
export interface Dispatch<S> {
<R>(thunkAction: ThunkInterface<R>): R;
}
} |
Yes, that works! I was just missing the import statement at the top of my augmentation file. Thank you @mhegazy! |
glad it is resolved. |
TypeScript Version: 1.8.0
Code Version: 1.2.0
Code:
I've put all the code in a gist, but the crux is that I want type system support for this line in
example.ts
:store.dispatch(thunkedAction(1) as any);
I don't want to have to cast the
thunkedAction
result toany
, but it's the only way I've found to make the compiler happy. It might be any of the following, but I've no idea which:typings
globals,typings
modules,npm
modules, and local.d.ts
filesI sincerely hope it's the latter, as then someone will be able to set me straight quickly.
Typings supporting the above code:
Failing augmentation for
redux.Dispatch
which seems to overridenode_modules/redux/index.d.ts
for the entire project:Expected behavior:
Per reduxjs/redux#1712, being able to augment
redux.Dispatch<S>
.Actual behavior:
Wailing, gnashing of teeth, dumpster fires, sirens in the distance.
The text was updated successfully, but these errors were encountered: