-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Troubleshooting : Type an untyped module #254
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
Hey @sw-yx, Is there a problem with my code formatting? I made sure to follow all the necessary steps. It will be great if you could review the changes I made and point me in the right direction. Thanks in advance! |
@arvindcheenu this looks like a good start! what about typing a React library that exports components or hooks? |
docs/basic/troubleshooting/types.md
Outdated
* Add the `declare` syntax for your desired module, say `my-untyped-module`– to the declaration file. | ||
```ts | ||
// inside typedec.d.ts | ||
declare module "my-untyped-module" |
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.
TIL that you can just do this without braces! Does it resolve every import to any
?
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.
yup. its a stopgap; i'd like for us to go a liiiitle bit beyond just this
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.
@ferdaber you can easily do away with every untyped import by declare module '*'
. Saves many lines of declare code but too hacky for my taste.
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.
yup. its a stopgap; i'd like for us to go a liiiitle bit beyond just this
Most of the hooks I use are either typed or custom made. So, I haven't encountered this problem yet.. I'll try to come up with some solution. Coz, it is gonna happen someday and I want to be ready for 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.
yup. ive done it 3-4 times but had to look it up every time. i shouldve taken the hint and put it in the cheatsheet!
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.
Woah, awesome stuff. We can add the lines 11-26 from your gist as an example for creating types for class components as a quick reference. This will also gel well with the previously stated troubleshooting steps.
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.
So, reviewing all that's been discussed, the hierarchical focus of topics in the troubleshooting section for this would be:
Working with Untyped Libraries
- The Lazy Way
- Using
declare module "*"
- Using
- The Hard Way
- With Hooks
useDarkMode()
example with explanation
- With Components
RR6
example [11-26] with explanation
- With Hooks
@sw-yx, Is this right or am I missing anything?
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.
yes sounds good! this will be a great help for others
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.
@sw-yx I've updated the docs and readme with the stuff we discussed, can you check and help solve the formatting problems?
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.
awesome! thank you so much, this works!! :) :) :)
Co-authored-by: swyx <[email protected]>
Co-authored-by: swyx <[email protected]>
Co-authored-by: swyx <[email protected]>
Co-authored-by: swyx <[email protected]>
Explained workarounds and possible solutions for typing an untyped React Hook or a React Component with Code Examples.
|
* Update README.md with Types Added changes to Troubleshooting types from #254 to README.md * Update README.md * fix prettier Co-authored-by: swyx <[email protected]>
Added Docs for Exporting types for Untyped libraries. PR for the Issue #245