microsoft / microsoft/TypeScript
TS2367: This condition will always return 'false' since the types 'Constructor<T>' and 'typeof Child' have no overlap.
Open
Nobody has claimed this yet.
Domain: Error Messages
Experience Enhancement
Good First Issue
Help Wanted
Suggestion
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 3.2.0-dev.20181011
Search Terms: TS2367
Code
abstract class Base<T> {
get Item(): T { return null }
}
class Child extends Base<Item> {
constructor(public data: any) { super() }
}
interface Item { }
declare type Constructor<T> = new (data: any) => Base<T>
function func<T>(constructor: Constructor<T>): void {
// TS2367: This condition will always return 'false' since the types 'Constructor<T>' and 'typeof Child' have no overlap.
if (constructor === Child) {
// do something
}
new constructor(null)
}
func(Child) // No errors
Expected behavior:
Compiles without errors.
Actual behavior:
test.ts:14:9 - error TS2367: This condition will always return 'false' since the types 'Constructor<T>' and 'typeof Child' have no overlap.
14 if (constructor === Child) {
~~~~~~~~~~~~~~~~~~~~~
Related Issues: #25642
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the supplied TypeScript reproduction or its Playground link and compare the behavior around TS2367 with related issue #25642. Trace why the generic Constructor comparison with typeof Child is rejected. Done means the example compiles without errors while preserving the existing constructor call behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100