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

fix: TypeScript support #268

Closed
wants to merge 1 commit into from
Closed

Conversation

nandorojo
Copy link
Contributor

See #25

@@ -2,6 +2,7 @@
"name": "react-strict-dom",
"version": "0.0.34",
"description": "React Strict DOM",
"types": "./dist/dom/index.d.ts",
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm surprised TS doesn't pick up the d.ts file next to the module entry, like flow does.
The types for web and native are slightly different. So how would TS users get the correct types in React Native?

Copy link

@efoken efoken Feb 5, 2025

Choose a reason for hiding this comment

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

Types should be defined in exports, using the types field does not make sense. But I am not sure if TypeScript can handle different types for web and native - maybe when using 2 different tsconfigs

Copy link
Contributor

Choose a reason for hiding this comment

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

Typescript often does pick up .d.ts files next to the JS files like Flow does. However, there's a bunch of tooling other than the Typescript Language Server that expects the types field in the package.json.

Additionally, RSD should have the same public types across web and native so hopefully that isn't a problem?

Copy link
Contributor

Choose a reason for hiding this comment

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

Nope, the exported API is not the same across platforms.

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we can create some kind of union type of the two and make that available for the types key?

I would also like to understand from @nandorojo what issues you're running into today. Typescript does resolve types from the .d.ts files that live alongside the .js files in my own testing.

Copy link
Contributor

Choose a reason for hiding this comment

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

@nandorojo @efoken See if #269 works for TS tooling integration

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should work. However, there should be a main single export that merges the types to let consumers implement both DOM and native.

Perhaps we can create some kind of union type of the two and make that available for the types key?

We technically don’t want a union since this would only expose types for one or the other. We should have a way to merge two different types. It shouldn’t be too hard, I could help with this.

Copy link
Contributor

Choose a reason for hiding this comment

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

We already successfully use Flow this way internally. So I don't think the types should be merged. I don't want people trying to use non-existent APIs on web and not getting type errors. The extra native API is only to be used in *.native.js files

Copy link

Choose a reason for hiding this comment

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

#269 looks good 👍 There should be no need for merged types

necolas added a commit that referenced this pull request Feb 6, 2025
Explicitly add 'types' to each conditional package export.

Close #268
@necolas
Copy link
Contributor

necolas commented Feb 12, 2025

Closing in favor of #269

@necolas necolas closed this Feb 12, 2025
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.

5 participants