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 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. |
|
@Kingwl hi can you let the bot to pack this? |
|
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? |
198754f to
f1b195d
Compare
|
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. |
|
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. |
|
@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 @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. |
|
@mmkal the bug has been fixed! |
Please move to #40468