-
Notifications
You must be signed in to change notification settings - Fork 3
feat(typescript): convert to typescript #51
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
Conversation
Matthew-Mallimo
left a comment
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.
Can the tests not rely on the build output?
Also, since we now have a build step, its best not to include the build in the repo (add to .gitignore), and update the release workflow to have a build step.
00aec0e to
6e48b3e
Compare
e661365 to
6b834c8
Compare
6b834c8 to
f132a90
Compare
017e34a to
febd8ef
Compare
febd8ef to
3f80d4e
Compare
2bd381f to
b8b1a31
Compare
b8b1a31 to
e82c5cb
Compare
src/index.ts
Outdated
|
|
||
| var contexts = {}; | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Allow any type for contexts | ||
| const contexts: { [key: string]: Context<any> | undefined } = {}; |
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.
Can we try to use unknown here instead, which is more true
src/index.ts
Outdated
| } | ||
| if (contexts[key]) { | ||
| return contexts[key]; | ||
| return contexts[key] as Context<T>; |
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.
If the provider part of the application uses
createSharedReactContext<{isModalOpen: boolean}>(...)
and the consumer uses
createSharedReactContext<{modalState: 'open' | 'closed'}>(...)
Then the Context produced will be lying to the consumer about the type of the context provided.
To make this code completely 'safe' it would need to always return Context<unknown> to force the consumer to validate the context shape explicitly.
update tests to tsx match types version with dep versions generic type change to main/types to exports change build to dist change target to es6 update types/react to 18 to provide modern context type switched to vitest and react-testing-library updated to stricter eslint update to react@17 install and enforce prettier during testing fixed snapshot removed timezone from setup change return type to Context<unknown>
e82c5cb to
3721d02
Compare
|
🎉 This PR is included in version 1.1.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This PR aims to convert this package to Typescript, allowing for both Javascript and Typescript projects to use it with added types for type-checking and IntelliSense.
Typescript was added as a dev dependency
File structure was changed to include src and build directories
tsc is used to transpile ts to js because of the package's simple output
ESLint was updated
Tests now use tsx and test index.ts in src
dist directory is gitignored and release runs build script
@types now matches installed dep versions (except for react)
types/react is installed @^18
react updated to 17
uses "exports" in package.json instead of main to supply built js and types
changed build dir to dist dir
changed target to es6 from 5 to remain at a version supporting all modern browsers
uses generic type for createReactSharedContext
enzyme testing replaced by vitest to upgrade react version
applied strict eslint rules
enforce prettier alongside eslint