Skip to content

Conversation

@xAndreiLi
Copy link
Contributor

@xAndreiLi xAndreiLi commented Nov 8, 2024

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

@xAndreiLi xAndreiLi requested a review from a team as a code owner November 8, 2024 02:58
@CLAassistant
Copy link

CLAassistant commented Nov 8, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@Matthew-Mallimo Matthew-Mallimo left a 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.

@xAndreiLi xAndreiLi force-pushed the feat/typescript branch 4 times, most recently from 00aec0e to 6e48b3e Compare November 8, 2024 19:46
@xAndreiLi xAndreiLi force-pushed the feat/typescript branch 2 times, most recently from e661365 to 6b834c8 Compare November 9, 2024 00:49
zacowan
zacowan previously approved these changes Dec 3, 2024
@xAndreiLi xAndreiLi force-pushed the feat/typescript branch 3 times, most recently from 017e34a to febd8ef Compare December 10, 2024 20:17
alnaranjo
alnaranjo previously approved these changes Dec 12, 2024
@xAndreiLi xAndreiLi force-pushed the feat/typescript branch 2 times, most recently from 2bd381f to b8b1a31 Compare December 12, 2024 16:57
zacowan
zacowan previously approved these changes Dec 13, 2024
code-forger
code-forger previously approved these changes Jan 7, 2025
@xAndreiLi xAndreiLi dismissed stale reviews from code-forger and zacowan via e82c5cb January 7, 2025 16:15
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 } = {};
Copy link
Member

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>;
Copy link
Member

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>
@alnaranjo alnaranjo merged commit 967de32 into americanexpress:main Jan 13, 2025
3 checks passed
@oneamexbot
Copy link
Contributor

🎉 This PR is included in version 1.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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.

8 participants