Closed mon-jai closed 2 months ago
This is a possible improvement. I thought of some methods, but was stuck on why TypeScript can't resolve types like ((a:number)=>number) | ((a:number)=>number)
. (playground)
@KermanX In the example you provided, f
is actually inferred as never
. You can verify this by hovering over type F
here: playground.
It seems that type annotation has no effect in this case: null!
is always inferred as never
in TypeScript. You’re essentially telling the compiler that "this is null
, but also not null
at the same time".
However, ((a: number) => number) | ((a: number) => number)
works as expected. You just need to initialize the variable with something that matches the type (e.g. null! as any
). (playground)
It seems that type annotation has no effect in this case:
null!
is always inferred asnever
in TypeScript. You’re essentially telling the compiler that "this isnull
, but also notnull
at the same time".However,
((a: number) => number) | ((a: number) => number)
works as expected. You just need to initialize the variable with something that matches the type (e.g.null! as any
). (playground)
Thanks a lot! Adding as any
works. However, in the first playground link, hovering f
shows const f: ((a: number) => number) | ((a: number) => number)
instead of never
, which seems a TypeScript bug.
However, in the first playground link, hovering
f
showsconst f: ((a: number) => number) | ((a: number) => number)
instead ofnever
, which seems a TypeScript bug.
Reported at: https://github.com/microsoft/TypeScript/issues/59626
Vue - Official extension or vue-tsc version
Same as playground
Vue version
3.5.0-beta.1
TypeScript version
5.6.0-beta
System Info
No response
Steps to reproduce
What is expected?
vue-tsc should infer the type of T correctly in the template.
What is actually happening?
Link to minimal reproduction
Playground link
Any additional comments?
No response