Uh oh!
There was an error while loading. Please reload this page.
Throw types - #40402
Conversation
alitaheri
commented
Sep 6, 2020
This is great, it can help develop and debug complicated type systems much more efficiently. I really hope it lands along with it's base PR on 4.1 😍 |
aminpaks
commented
Sep 6, 2020
Why would you use typeMustNumber<T>=Textendsnumber ? T : throw `Expected, but found "${typeofT}"`
|
Jack-Works
commented
Sep 6, 2020
It's can be changed to another keyword if there is a better alternative |
mmkal
commented
Sep 7, 2020
@Jack-Works this looks awesome. Is there a playground link we can try? I have a type assertions library (expect-type) and I'd like to see if I can use this to improve the error messages. |
Jack-Works
commented
Sep 7, 2020
@Kingwl hi can you let the bot to pack this? |
Kingwl
commented
Sep 7, 2020
sure. @typescript-bot pack this |
Oh seems like the bot won't pack this until no test error, I'll handle this later Now it can pack without error, sorry @Kingwl can you call the bot again? |
As your wish. :XD @typescript-bot pack this. |
Hey @Kingwl, I've packed this into an installable tgz. You can install it for testing by referencing it in your and then running There is also a playground for this build. |
I'm gonna re-pack, a bunch of PRs got merged on monaco / monaco-ts last night which broke the playground build - I think I fixed it. @typescript-bot pack this. |
orta
commented
Sep 9, 2020
Third time lucky ( see #40445 ) @typescript-bot pack this. |
Hey @orta, I've packed this into an installable tgz. You can install it for testing by referencing it in your and then running There is also a playground for this build. |
mmkal
commented
Sep 9, 2020
@Jack-Works trying this out on my library now, and it's working beautifully. I did notice one small issue, though. Throw types for generic functions inside generic interfaces can get replaced with interfaceExample<T>{tOnly: <U>()=>throw`T: ${typeofT}`
uOnly: <U>()=>throw`U: ${typeofU}`
tAndU: <U>()=>throw`T: ${typeofT}, U: ${typeofU}`}declareconstex: Example<{foo: string}>ex.tOnly<{bar: string}>()// Error looks good: Type instantiated results in a throw type saying: T: { foo: string; }ex.uOnly<{bar: string}>()// Error looks good: Type instantiated results in a throw type saying: U: { bar: string; }ex.tAndU<{bar: string}>()// Error looks bad: Type instantiated results in a throw type saying: Unknown |
Jack-Works
commented
Sep 10, 2020
Thanks @mmkal , I'll try to investigate the bug later |
Jack-Works
commented
Sep 10, 2020
I found another potential usage. This PR might be able to resolve #18433 (Dangerous "name" global). |
hi everyone please move to #40468 cause the base branch has been merged so this PR is closed automatically. |
Jack-Works
commented
Sep 10, 2020
@mmkal the bug has been fixed! |
Please move to #40468