Skip to content

Basic Typescript typings #70

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

Closed
wants to merge 8 commits into from
Closed

Basic Typescript typings #70

wants to merge 8 commits into from

Conversation

denisw
Copy link
Contributor

@denisw denisw commented Jan 6, 2019

This PR is a less ambitious alternative to #38. It is not a rewrite in TypeScript, but simply adds a separate type definition file (index.d.ts), similar to how TypeScript support is provided in the core Redux repo. Also like in the case of Redux, the typings come with a set of test TypeScript files run through typings-tester to ensure that the typings work as intended.

I am sure that some of the typings could be made even more precise. I'd say, though, that this is a decent first step that we can iterate on later, and it should be definitely better for TypeScript users than not having typings at all.

denisw added 3 commits January 5, 2019 14:10
Also included is a typings-tester integration with
some initial tests, plus the configuration needed
to include `index.d.ts` in the release distribution.
@netlify
Copy link

netlify bot commented Jan 6, 2019

Deploy preview for redux-starter-kit-docs ready!

Built with commit b84231f

https://deploy-preview-70--redux-starter-kit-docs.netlify.com

denisw added 5 commits January 6, 2019 16:14
The generated action creator is now typed such that it returns a
PayloadAction when called with a payload argument, and a payload-less
Action when called without arguments.
@markerikson
Copy link
Collaborator

This looks interesting. But, how much effort would it be to either push #38 forward, or just convert the codebase to TS from scratch? createSlice in particular shouldn't be too hard given that it's really the code from https://github.com/neurosnap/robodux but compiled to JS. selectorator v4 is now written in TS and has typings, so that issue seems to be resolved.

@denisw
Copy link
Contributor Author

denisw commented Jan 6, 2019

I took the definition file approach because it seemed less intrusive, and more it line with what has been done for core Redux. But I'd also be happy to continue the TypeScript rewrite work started in #38 instead. From the perspective of a redux-starter-kit user, there is no perceivable difference; it is a pure manner of what is preferable from a maintainers' point of view. What do you think?

Regarding createSelector(), this PR already re-exports selectorator's upstream typings. Same for createNextState() from immer's produce(). I didn't know createSlice(). I didn't know that createSlice() came from a TS library, but robodux's createSlice() doesn't seem to have an explicit return type defined, so in that regard the typing in this PR is better because it doesn't rely on possibly changing rules of TypeScript's type inference.

@markerikson
Copy link
Collaborator

If we're gonna do TS stuff, I'd rather just go ahead and rewrite it in TS now, before we make any further changes.

@Dudeonyx actually seems to have done the TS conversion in https://github.com/Dudeonyx/redux-ts-starter-kit to some extent, and just offered to help out: https://www.reddit.com/r/reactjs/comments/ad6cmt/check_out_my_first_serious_npm_package/ .

@denisw
Copy link
Contributor Author

denisw commented Jan 7, 2019

Alright! I'm going to pick up the TypeScript rewrite work then. As a first step, I'm going to open a PR with an upgrade to Babel 7 so that we can use @babel/preset-typescript.

@denisw
Copy link
Contributor Author

denisw commented Jan 7, 2019

I opened the Babel 7 PR as #71.

Closing this PR.

@denisw denisw closed this Jan 7, 2019
This was referenced Jan 7, 2019
markerikson pushed a commit that referenced this pull request Apr 20, 2021
* Fix return types for matchers
* use action matchers, retype matched types, tests
* extract error types for thunk matchers

Co-authored-by: Lenz Weber <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants