-
Notifications
You must be signed in to change notification settings - Fork 13
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
Conversation
__tests__/babel-wrapper.js
Outdated
@@ -0,0 +1,3 @@ | |||
module.exports = require('babel-jest').createTransformer({ | |||
rootMode: 'upward', |
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.
I don't think you need that file, it's only needed when running jest in a mono-repo (using yarn workspaces)
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.
correct done
build/index.js
Outdated
@@ -0,0 +1,117 @@ | |||
"use strict"; |
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.
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
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.
correct done
countries.ts
Outdated
@@ -0,0 +1,9532 @@ | |||
import { CountryRaw } from './types'; | |||
|
|||
const countries: { [countryCode: string]: CountryRaw } = { |
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.
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)
const countries: { [countryCode: string]: CountryRaw } = { | |
const countries = { |
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.
done
package.json
Outdated
"test": "jest --env=node --colors", | ||
"lint": "eslint --ext ts ./", | ||
"build": "tsc", | ||
"typecheck": "tsc" |
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.
Usually typecheck
uses --noEmit
so it only checks types without emitting js files. Otherwise it's exactly the same as build
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.
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( |
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.
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)
?
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.
it was for backwards compatibility but you're right it's better to remove it
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.
done
Refactor
.ts
in.js
for retro compatibility