-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Typescript does not explicitly pass undefined, which breaks intelliSense [5.5.2] #58976
Comments
NOTE WELL: I'm not a member of the TS team, just a If you're trying to report a bug in the TypeScript language, you should make an effort to reproduce it with a small self-contained example, one that fits in a single file and does not need to pull in type definitions from other libraries like react or next. Codesandbox is not the TS playground. The vast majority of bugs can be demonstrated in just a few lines of code. If you're just having trouble with using TypeScript along with these other technologies, you should consider closing this and opening a question of Stack Overflow or in the TypeScript discord channel. Then, assuming you follow their guidelines and someone responds, if it turns out that the problem really is a bug in TypeScript you might be directed back here with a truly minimal example, or someone might point to an existing bug (like maybe #38849 or #50139) so you can track the progress (or lack thereof) there. You mention "conditional types" but there are no conditional types here. You presumably mean union types instead. Your search terms just look like your title, indicating maybe you didn't really search first? If you search for "react union intellisense", do any of the results look like your problem? |
I'm not really seeing a bug demonstrated here |
That is, logically, I always need to explicitly specify undefined for each props so that I can display types in intelliSense under this condition: if (typeof props.href !== "undefined") After all, undefined is always passed there by default, if there is no defined props. The question is, why is this done? |
it would be normal if it simply did not define and, for example, with the value "a", it would not give an error. So why, if it defines the necessary types, not output them in intelliSense? |
By the way, here's another moment from issue #38849. I don't explicitly specify href and the types work for me, but they don't work in jsx |
Also, after a couple of actions, intelliSense will stop working for calling the function: |
He expects the absence of the Here's a simplified example: Playground Auto completion for |
I understand that, yes, but just undefined is always passed by default in the component if there are no props. From my point of view, I understand that this is not critical, but it is inconvenient that you need to explicitly specify undefined. Rather, it makes no sense to specify undefined for props. |
In the playground, in your example, such a thing does not appear: Although it is much more logical and better than that: I don't know, I don't think this is really convenient, and it would be better to fix it, because if props was not passed, it is equal to Although the default values were indicated in this issue #50139. I hope |
This issue has been marked as "Not a Defect" and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
🔎 Search Terms
Typescript does not explicitly pass undefined, which breaks intelliSense
🕗 Version & Regression Information
⏯ Playground Link
https://codesandbox.io/p/devbox/test-typescript-q89n2h
💻 Code
🙁 Actual behavior
Without explicitly specifying href={undefined}, conditional types do not work
🙂 Expected behavior
Instead of the typical: "button" | "submit" | "reset" | undefined
I get the type: string | undefined
Additional information about the issue
Let's move on. Why do I lose button typing if I don't have an href?
![image](https://private-user-images.githubusercontent.com/59291123/342071909-98e8da45-a6dd-41ea-8b6b-52f3910c873c.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg4MzYxNzEsIm5iZiI6MTczODgzNTg3MSwicGF0aCI6Ii81OTI5MTEyMy8zNDIwNzE5MDktOThlOGRhNDUtYTZkZC00MWVhLThiNmItNTJmMzkxMGM4NzNjLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA2VDA5NTc1MVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTAwZTc4MDNjY2NiZjk3MzY5ODliYzBmY2VhNDE4OTc3YmI0NmQzODlhOWMxOGE0YmI3NjI4ZmRmNGY5NmI0ZjAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.vC4BFIj3Wu6DBSVSP1v92E9_Wh48Z_cjxIPR-8u6X3E)
For some reason, button types are shown here only if undefined is explicitly specified
![image](https://private-user-images.githubusercontent.com/59291123/342071958-0042c7bc-a850-48d1-a000-340ed5568bd7.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg4MzYxNzEsIm5iZiI6MTczODgzNTg3MSwicGF0aCI6Ii81OTI5MTEyMy8zNDIwNzE5NTgtMDA0MmM3YmMtYTg1MC00OGQxLWEwMDAtMzQwZWQ1NTY4YmQ3LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA2VDA5NTc1MVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWYxZjkyODRmYmYwODQxYzhjNGU2MTIxZDkxYTEzNTQ0NjE5YzQzYWI0NDBkZjQ5NDhhYmQ5OGI4NDU4ZTQ0N2ImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.KW8wqxuPgp49U7GSYbFnvt3bktttBfCj5xJyFkBab_g)
It may then open up a new issue for this problem that typescript does not implicitly define undefined (props that do not pass)
It determines if there is some kind of internal typing, but it is not displayed when opening intelliSense:
![image](https://private-user-images.githubusercontent.com/59291123/342091000-f89b3b72-af90-419e-9ae4-a0f96081ddb7.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg4MzYxNzEsIm5iZiI6MTczODgzNTg3MSwicGF0aCI6Ii81OTI5MTEyMy8zNDIwOTEwMDAtZjg5YjNiNzItYWY5MC00MTllLTlhZTQtYTBmOTYwODFkZGI3LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA2VDA5NTc1MVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWRiNjY4Y2YyODYwNmJkMTE2MDdlY2I2NTY5YmNmNGEzMTM5MTUxMzllNmY5MTBiYzZlYTNlY2Y3MGQxMTk5YTYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.11ZyRCf9J7E7ipnrWVSDaTUZ9s4UXg0kA6dEFof4NcE)
The text was updated successfully, but these errors were encountered: