Skip to content
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

Refactor: rewrite code in Typescript #13

Merged
merged 11 commits into from
Mar 16, 2021
Merged

Refactor: rewrite code in Typescript #13

merged 11 commits into from
Mar 16, 2021

Conversation

marchah
Copy link
Owner

@marchah marchah commented Mar 13, 2021

Refactor

  • Rewrite code in Typescript
  • Compile .ts in .js for retro compatibility

@marchah marchah self-assigned this Mar 13, 2021
@@ -0,0 +1,3 @@
module.exports = require('babel-jest').createTransformer({
rootMode: 'upward',

Choose a reason for hiding this comment

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

I don't think you need that file, it's only needed when running jest in a mono-repo (using yarn workspaces)

Copy link
Owner Author

Choose a reason for hiding this comment

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

correct done

build/index.js Outdated
@@ -0,0 +1,117 @@
"use strict";

Choose a reason for hiding this comment

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

Hm I don't think built files should be versioned. My understanding with ts libraries is that they publish the built files to npm but only version ts files

Copy link
Owner Author

Choose a reason for hiding this comment

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

correct done

countries.ts Outdated
@@ -0,0 +1,9532 @@
import { CountryRaw } from './types';

const countries: { [countryCode: string]: CountryRaw } = {

Choose a reason for hiding this comment

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

I think you should drop the annotation, as it would prevent typescript to actually infer the valid keys (unless you don't want typescript to actually autocomplete country codes)

Suggested change
const countries: { [countryCode: string]: CountryRaw } = {
const countries = {

Copy link
Owner Author

Choose a reason for hiding this comment

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

done

package.json Outdated
"test": "jest --env=node --colors",
"lint": "eslint --ext ts ./",
"build": "tsc",
"typecheck": "tsc"
Copy link

@gaelollivier gaelollivier Mar 15, 2021

Choose a reason for hiding this comment

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

Usually typecheck uses --noEmit so it only checks types without emitting js files. Otherwise it's exactly the same as build

Copy link
Owner Author

Choose a reason for hiding this comment

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

correct done

index.ts Outdated
* Add search function to each country and map each country by alpha2
*/
const listCountries = keyBy(cloneDeep(countriesRaw), 'alpha2');
const countries: { [countryCode: string]: Country } = Object.keys(listCountries).reduce(

Choose a reason for hiding this comment

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

This means any script importing the library will run this reduce on all countries. Is this an API that you need to support for backwards compatibility? Couldn't it be changed to something like getProvinceByName(countries.US) ?

Copy link
Owner Author

Choose a reason for hiding this comment

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

it was for backwards compatibility but you're right it's better to remove it

Copy link
Owner Author

Choose a reason for hiding this comment

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

done

@gaelollivier
Copy link

I ran yarn and it re-generated yarn.lock so you might need to update it:
image

@marchah marchah marked this pull request as ready for review March 16, 2021 00:01
@marchah marchah merged commit 6571bbc into master Mar 16, 2021
@marchah marchah deleted the refactor/typescript branch March 16, 2021 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants