-
Notifications
You must be signed in to change notification settings - Fork 80
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
Support For TypeScript #46
Comments
Yes! Absolutely. |
I have this almost done :) Please be patient for following few days :) |
@karolmajta hey, any update to this? Anything I can help you with? |
@karolmajta also curious to see what you've done. |
This is the module I've created for use in my projects. So far it seems to fit most of the situations I've thrown at it. https://gist.github.com/deldreth/df87cfd62ef91b9fce6f66dae01f40b0 |
I had completely forgotten about this. I've actually updated the createReducer type signature for most of my use cases. https://gist.github.com/deldreth/df87cfd62ef91b9fce6f66dae01f40b0#file-reduxsauce-d-ts-L34 That includes providing a generic state type to handlers. This has given me better error breakdown per reducer. I'm sure I could put together a PR for the typedef based on my gist. |
@deldreth create a PR please <3 |
The typings I've made for createReducer and createActions work well enough for most cases but you won't get full type safety with parameters to action creators from createActions. I think just given the runtime nature of creaeActions and createTypes makes it difficult to infer the types of either the resolved object or template literal of the functions respectively. I'm hoping someone can prove me wrong on that. In my use cases I've been writing classic types/creators to get the type safety I'd expect. export const enum Types {
SOME_THING = 'SOME_THING',
}
export interface SomeThingAction extends AnyAction {
type: Types.SOME_THING;
thing: string;
}
const someThing = (thing: string): SomeThingAction => ({
type: Types.SOME_THING,
thing,
});
// Export your creators object
export default {
someThing,
}; |
My version of reduxsauce.d.ts using template for creating actions https://gist.github.com/Elvinra/a91a677691b868b956d87d9836745b12 based on the file of @deldreth |
That's a good approach. I submit a slightly more type safe usage implementation for your consideration. Within my team we disallow implicit any so having explicit types for actions is necessary. import { AnyAction } from 'redux';
import { Actions, createActions } from 'reduxsauce';
export interface AppTypes {
APP_START: 'APP_START';
SOME_PARAM: 'SOME_PARAM';
}
export interface AppStartAction extends AnyAction {
type: AppTypes['APP_START'];
payload: {};
}
export interface SomeParamAction extends AnyAction {
type: AppTypes['SOME_PARAM'];
payload: {
thisIsIt: string,
};
}
interface AppActions {
appStart (): AppStartAction;
someParam (thisIsIt: string): SomeParamAction;
}
export const { Types, Creators } = createActions<AppActions, AppTypes>({
appStart: null,
someParam: [ 'thisIsIt' ],
});
Creators.appStart();
Creators.someParam('things'); In this situation you'll get type safety on your reducers or elsewhere (middlewares?) you're using the return of an action creator. |
Is this topic still maintained? I really think that this library in combination with typescript makes a huge step into the right direction! |
I'm not sure. #58 is still open with no feedback. |
Ya, my bad. I'm having a hard time keeping up with the 5 or 6 open source projects I'm responsible for. 😅 I need help. 😆 I don't use redux much anymore and by extension this library. I do, however, use the heck out of Typescript, so this is very very welcome. I'll take a look at #58 this week once I finish up a new release on another oss project. I took at quick scan of the PR and it looks great! ❤️ |
@skellock any update ? |
any update on this? |
Curious if there is any intent to support TypeScript down the road?
The text was updated successfully, but these errors were encountered: