Throw types - #40402
Conversation
|
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 😍 |
|
Why would you use type MustNumber<T> = T extends number ? T : throw `Expected, but found "${typeof T}"`
|
|
It's can be changed to another keyword if there is a better alternative |
640b5f8 to
198754f
Compare
|
Jack Works (@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. |
|
Wenlu Wang (@Kingwl) hi can you let the bot to pack this? |
|
sure. TypeScript Bot (@typescript-bot) pack this |
|
Heya Wenlu Wang (@Kingwl), I've started to run the tarball bundle task on this PR at 198754f. You can monitor the build here. |
|
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 Wenlu Wang (@Kingwl) can you call the bot again? |
198754f to
f1b195d
Compare
|
As your wish. :XD TypeScript Bot (@typescript-bot) pack this. |
|
Heya Wenlu Wang (@Kingwl), I've started to run the tarball bundle task on this PR at f1b195d. You can monitor the build here. |
|
Hey Wenlu Wang (@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 (@typescript-bot) pack this. |
|
Third time lucky ( see #40445 ) TypeScript Bot (@typescript-bot) pack this. |
|
Heya Orta Therox (@orta), I've started to run the tarball bundle task on this PR at f1b195d. You can monitor the build here. |
|
Hey Orta Therox (@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. |
|
Jack Works (@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 interface Example<T> {
tOnly: <U>() => throw `T: ${typeof T}`
uOnly: <U>() => throw `U: ${typeof U}`
tAndU: <U>() => throw `T: ${typeof T}, U: ${typeof U}`
}
declare const ex: 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 |
|
Thanks Misha Kaletsky (@mmkal) , I'll try to investigate the bug later |
|
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. |
|
Misha Kaletsky (@mmkal) the bug has been fixed! |
Please move to #40468