Uh oh!
There was an error while loading. Please reload this page.
Allow Boolean() to be used to perform a null check - #29955
Allow Boolean() to be used to perform a null check#29955Ryan Cavanaugh (RyanCavanaugh) merged 3 commits into
Conversation
beshanoe (beshanoe)
commented
Mar 5, 2019
Hi, this is a really good initiative, do you think we can skip specifying generic after this |
Ryan Cavanaugh (RyanCavanaugh)
commented
Mar 5, 2019
TypeScript Bot (@typescript-bot) test this |
Heya Ryan Cavanaugh (@RyanCavanaugh), I've started to run the extended test suite on this PR at 24e7e1c. You can monitor the build here. It should now contribute to this PR's status checks. |
Forbes Lindesay (ForbesLindesay)
commented
Mar 6, 2019
beshanoe (@beshanoe) I think that may be sufficient to allow us to skip specifying generic parameters. I'm not sure though without testing it. I found: functionB<T>(value: T): value is Exclude<T,false|null|undefined|''|0>{returnBoolean(value);}was already sufficient, but adding prototypes/new functions to the interface forces you to be explicit. |
Ryan Cavanaugh (RyanCavanaugh)
commented
Mar 6, 2019
Forbes Lindesay (@ForbesLindesay) can you merge this up with master? This will allow us to re-run the RWC suite to evaluate the effects of this on our real-world code database |
… boolean-null-check
Forbes Lindesay (ForbesLindesay)
commented
Mar 18, 2019
Ryan Cavanaugh (@RyanCavanaugh) sorry I didn't see your message. I've merged it now. |
Forbes Lindesay (ForbesLindesay)
commented
Mar 25, 2019
Ryan Cavanaugh (@RyanCavanaugh) any update on this? |
Ryan Cavanaugh (RyanCavanaugh)
commented
Mar 28, 2019
TypeScript Bot (@typescript-bot) test this |
Heya Ryan Cavanaugh (@RyanCavanaugh), I've started to run the extended test suite on this PR at 37bb42c. You can monitor the build here. It should now contribute to this PR's status checks. |
Ryan Cavanaugh (RyanCavanaugh)
commented
Mar 28, 2019
RWC is actually clean, ignore ❌ |
Forbes Lindesay (ForbesLindesay)
commented
Apr 8, 2019
Ryan Cavanaugh (@RyanCavanaugh) any chance we can merge this? It's been a while and it's a very simple fix. |
☝️ 🙏 |
Tom Crockett (pelotom)
commented
Apr 29, 2019
Resolves #31164. |
Kalashnikov Igor (silentroach)
commented
Jun 24, 2019
broken by #31515 |
Matt Greer (city41)
commented
Nov 6, 2019
This would be a great addition to the language. Have there been any plans on when it might land? 3.8 maybe? |
Maksim (pret-a-porter)
commented
Dec 23, 2019
Matt Greer (@city41) Unfortunately it is still open #16655 Really strange thing, that behaviour of |
Shanon Jackson (ShanonJackson)
commented
Feb 22, 2023
Ryan Cavanaugh (@RyanCavanaugh) Can we revive this. Still continues to prevent usage of the .filter(Boolean) syntax sugar today. |
Check out ts-reset. |
Steve Bennett (stevage)
commented
Mar 10, 2023
Is there a good workaround in the meantime? I'm not sure how else to express |
Jake Bailey (jakebailey)
commented
Mar 10, 2023
You can use type guards: ["",undefined,"test"].filter((x): x is string=>typeofx==="string") |
Shanon Jackson (ShanonJackson)
commented
Mar 15, 2023
Works universally for any |
Jonny Lee (jonny133)
commented
Nov 6, 2023
The code in #29955 (comment) more completely shows the result of |
Fixes#16655
This allows code like:
to be written and to typecheck. Unfortunately the generic type still has to be specified, otherwise TypeScript picks the other, less specific overload of
.filter.