-
-
Notifications
You must be signed in to change notification settings - Fork 849
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
Migrate source code to TypeScript [WIP] #128
Conversation
@mweststrate can you have a quick look (especially on the few changes introduced in d08cf3a) and let me know if so far it seems good before I go on and start adding types? Also, are you okay with removing tests/flow/ts.ts? I don't think we need it anymore as the types will be embedded in the source code and verified by ts and by the tests. |
@@ -14,7 +14,7 @@ import {produceEs5} from "./es5" | |||
* @param {Function} producer - function that receives a proxy of the base state as first argument and which can be freely modified | |||
* @returns {any} a new state, or the base state if nothing was modified | |||
*/ | |||
export default function produce(baseState, producer) { | |||
export default function produce(baseState, producer?) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these parameters have types defined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eventually yes. I think the reason I added the question mark was to try to make __tests__/flow/ts.ts
happier
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The question mark is correct though, produce can be invoked with one argument, basically there are three forms:
produce(baseState, producer) => nextState
produce(producer) => baseState => nextState // curried form
produce(producer, initialState) => baseState => nextState // curried form with default state
@urish looking good so far |
@urish preferrably leave the |
@mweststrate cool, I'm on it. I created some initial jest integration for TypeWiz, though hitting some strange issues when running the instrumented test code - I will have to dig in further and isolate them. It could be that Proxies pose some challenges for TypeWiz, we will find out soon :) |
Update: seems like the Proxies are indeed giving TypeWiz a hard time - the only way I could get all of the tests to pass with TypeWiz was by removing the code that tries to detect the shapes of arrays and object literals. Otherwise, we get all sort of infinite loops and other fun stuff. Here are the stats I gathered so far:
Another challenge is collecting the type information from the test cases when they finish running. I haven't found any straightforward way to do it through the jest plugin, so right now I'm simply adding the following code at the beginning of each test file: afterAll(() => {
require("fs").writeFileSync(
"frozen-types.json",
JSON.stringify((global as any).$_$twiz.get())
)
}) it gets the job done, but then I will still have to merge the collected type info from the different test suites. I am not sure how useful this would be without Array / Object type inference - I will give it another try tomorrow, and then I hope to share another report here. |
- renamed source files .js -> .ts - install types for deep-freeze, lodash.clonedeep - install ts-jest, rollup-plugin-typescript2
build passes now
Closing for inactivity, and since this lib doesn't require much active development TS is not that mandatory |
noImplicitAny
(typewiz)