-
-
Notifications
You must be signed in to change notification settings - Fork 521
Proposed documentation clarification for migrating a Typescript project #1240
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
Comments
I don't think that's the case, you should still keep setting The type errors might be from not restarting the TS lang server? It can get a little confused when you change config options. |
Thanks for taking a look! Comments below: Build-time resolution You are of course correct.
Type checking If I add that line for
The error (which shows up in any line containing JSX) is:
|
That's bizarre -- do you have a repo I can take a look at by chance? Setting the JSX transform shouldn't be creating type errors to my knowledge. |
Of course! Project is here: https://github.com/nkprasad12/morcus-net
|
Thanks, that's helpful! It looks like the type errors are "correct", or at least meant to be occurring. I don't know why this is, it makes no sense to me, but when you don't set So this isn't so much of a config issue as it is a types issue, TS just behaves rather oddly here and keeps supplying your app with React's types (which therefore avoid the types issues) when you haven't set |
Some issues I've come across:
|
Going to close this on out as we got this corrected in your repo |
First of all: thank you for such a detailed look! I definitely was not expecting anything like this. After your heroic effort, I brought in your fixes to my project and patched in your changes to my Two issues I fixed that I wanted to quickly flag: One issue was in the following snippet:
This worked with
while I think The other issue I was related to type widening, which I am not exactly sure why
to
to get things to work correctly. I am no Typescript expert so I don't know if this is the Thanks again for your help on this! I really appreciate it. |
Actually, they were released earlier today as 10.26.0, should be able to bump your Preact version & get access to them.
Not sure to be quite honest. It's possible it needs to be added here but I'm not familiar enough myself with our TS event handling. For Adding pkg dependencies just for types is a bit weird, especially as we ship our types with the module (unlike React). But no problem! Glad I could be of some help. |
Uh oh!
There was an error while loading. Please reload this page.
Hi Preact team -
Suggestion
Please consider adding a note to the Typescript preact/compat configuration section indicating that if the path aliases for
compat
are set up, there is no need to specifyjsxImportSource: preact
in thetsconfig
. This may seem obvious but for someone not as used to messing around with the toolchain, such a message could save a lot of time.Thanks for your hard work on the project!
Background
I was following along https://preactjs.com/guide/v10/typescript
I first followed the Typescript configuration section and added
"jsxImportSource": "preact"
to my config.I then moved on to the Typescript preact/compat configuration section and added the following:
The result was that every single file in my project with JSX had a bunch of type errors for reasons I couldn't understand.
Solution
Eventually (after a few hours of debugging) I realized that once the path aliases are set up,
"jsxImportSource": "preact"
is not needed.After that, Typescript is happy, my site works as expected, and all my unit and E2E tests pass.
The text was updated successfully, but these errors were encountered: