Cannot define a union type with a new signature type
See original GitHub issueThis currently gives me parse error:
class A {
}
function test(x: string | new() => A) {
~~~~~~~~~~ parse error
}
Though this works:
function test(x: new() => A) {
}
Issue Analytics
- State:
- Created 8 years ago
- Comments:8 (7 by maintainers)
Top Results From Across the Web
Union type with incompatible signatures - Stack Overflow
I'm trying to add TypeScript support and it is proving challenging. The latest problem is that I'm getting this error: TS2349: This expression ......
Read more >Quick fix for 'unions can't be used in index signatures ... - GitHub
Gives this error message: An index signature parameter type cannot be a union type. Consider using a mapped object type instead.
Read more >Handbook - Unions and Intersection Types - TypeScript
A common technique for working with unions is to have a single field which uses literal types which you can use to let...
Read more >Type Aliases vs Interfaces in TypeScript - DEV Community
Type aliases and interfaces can be combined into one type using unions or intersections, but cannot be combined into an interface .
Read more >An index signature parameter type cannot be a literal type or a ...
The error An index signature parameter type cannot be a literal type or a generic type occurs when we use an incompatible type...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’d say that it’s advantageous to users to disallow this, since we force writers to be explicit for future readers.
But yes, I think parsing this and reporting an error would be helpful, such as:
or the following two separately:
Hit this recently with intersection types. Patch (was a bit tricky) uses this message :
Invalid type. To avoid ambiguity, add parentheses: '(new() => void)'