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

Troubleshooting : Type an untyped module #254

Merged
merged 14 commits into from Aug 2, 2020
Merged

Troubleshooting : Type an untyped module #254

merged 14 commits into from Aug 2, 2020

Conversation

isarvindone
Copy link
Collaborator

Added Docs for Exporting types for Untyped libraries. PR for the Issue #245

Added Docs for Exporting types for Untyped libraries. PR for the Issue #245
Updated Readme for Troubleshooting for the issue Typing an untyped library. Addresses issue #245.
@isarvindone
Copy link
Collaborator Author

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!

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@swyxio
Copy link
Collaborator

swyxio commented Jul 22, 2020

@arvindcheenu this looks like a good start! what about typing a React library that exports components or hooks?

* 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"
Copy link
Collaborator

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?

Copy link
Collaborator

@swyxio swyxio Jul 22, 2020

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

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator

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!

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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

  1. The Lazy Way
    • Using declare module "*"
  2. The Hard Way
    1. With Hooks
      • useDarkMode() example with explanation
    2. With Components
      • RR6 example [11-26] with explanation

@sw-yx, Is this right or am I missing anything?

Copy link
Collaborator

@swyxio swyxio Aug 2, 2020

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

Copy link
Collaborator Author

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?

Copy link
Collaborator

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!! :) :) :)

isarvindone and others added 5 commits July 23, 2020 15:18
Co-authored-by: swyx <shawnthe1@gmail.com>
Co-authored-by: swyx <shawnthe1@gmail.com>
Co-authored-by: swyx <shawnthe1@gmail.com>
Co-authored-by: swyx <shawnthe1@gmail.com>
Explained workarounds and possible solutions for typing an untyped React Hook or a React Component with Code Examples.
@isarvindone isarvindone marked this pull request as ready for review August 2, 2020 18:43
@danger-public
Copy link

danger-public commented Aug 2, 2020

Warnings
⚠️

Found "Typescript" in < - you want to use "TypeScript"

Generated by 🚫 dangerJS against 78a2df6

@swyxio swyxio merged commit da85af2 into typescript-cheatsheets:master Aug 2, 2020
swyxio pushed a commit that referenced this pull request Aug 3, 2020
* Update README.md with Types

Added changes to Troubleshooting types from #254 to README.md

* Update README.md

* fix prettier

Co-authored-by: swyx <wanshawn@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants