Skip to content

CHECKOUT-2507: Convert DataStore module into TypeScript #35

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

Merged
merged 3 commits into from
Jan 21, 2018

Conversation

davidchin
Copy link
Contributor

@davidchin davidchin commented Jan 18, 2018

What?

  • Convert DataStore module into TypeScript.
  • Add tslint

Why?

  • To enable static type checking.
  • This is our first step to convert our codebase into TypeScript.
  • Please note that I'm using the default configuration provided by tslint. I have added some overrides in order to match with the configuration we have for JavaScript files (enforced by eslint). We will need to revisit the rules some time in the future.

Testing / Proof

  • Unit

@bigcommerce/checkout @bigcommerce/payments

return result;
}

return Object.assign({}, result, { [key]: newState });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come we're no longer using object spread here anymore? Is does TS not play well with spread?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently there's an ongoing issue with the use of the spread operator with generics. microsoft/TypeScript#13557

We are using the default configuration provided by `tslint`. We have
added some overrides in order to match with the configuration we have
for JavaScript files (enforced by `eslint`). We will need to revisit the
rules some time in the future.
@davidchin davidchin force-pushed the data_store_typescript branch from fe91b38 to eb4f14c Compare January 19, 2018 01:40
@@ -2,7 +2,7 @@ import deepFreeze from './deep-freeze';

describe('deepFreeze()', () => {
it('throws error if mutating object', () => {
const object = deepFreeze({ message: 'Foobar' });
const object = deepFreeze({ message: 'Foobar' }) as any;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to typecast to any in order to bypass the TypeScript compiler check. Otherwise, because deepFreeze returns Readonly<T>, you're not able to assign any new values anyway. But I want to keep the tests because I want to test what would happen in JS environment where type checking is not enforced.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should probably also chuck a comment about this statement with the same contents as in your GH comment...

Copy link

@software-artificer software-artificer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Really exciting to see this TypeScript movement!

@@ -0,0 +1,6 @@
export default interface Action<P = any, M = any> {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks weird to me that we are using single letters for generic type names. I would strongly suggest having meaningful names here.

@@ -2,7 +2,7 @@ import deepFreeze from './deep-freeze';

describe('deepFreeze()', () => {
it('throws error if mutating object', () => {
const object = deepFreeze({ message: 'Foobar' });
const object = deepFreeze({ message: 'Foobar' }) as any;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should probably also chuck a comment about this statement with the same contents as in your GH comment...

@@ -1,6 +1,6 @@
export default interface Action<P = any, M = any> {
export default interface Action<TPayload = any, TMeta = any> {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, I just commented about bad habit of naming types for generics as single letters, and here you go... you just fixed them!

Copy link
Contributor

@icatalina icatalina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a comment, rest looks good :)

*/
subscribe(subscriber, ...filters) {
let state$ = this._state$;
subscribe(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should consider aliases for this type descriptions. They seem like they could be reused and make the signature hard to read.

subscribe(subscriber: Subscriber, ...filters: Array<Filter>): Subscription {

Not sure what the rest of @bigcommerce/frontend feel about this...

@davidchin davidchin force-pushed the data_store_typescript branch from eb4f14c to 036a2b8 Compare January 19, 2018 04:59
@davidchin
Copy link
Contributor Author

Thanks guys. I've amended the last commit to include the suggested changes.

@software-artificer
Copy link

Thanks a lot DC, really nice work!

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.

4 participants