microsoft / microsoft/TypeScript

Missing error on class extending union of incompatible constructor types

Open
#42,213 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Domain: classes
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

TypeScript Version: 4.2.0-dev.20210105, worked in v3.6.3, regressed in v3.7

Search Terms: is not a constructor function type

Expected behavior:

Error: Type 'typeof Base | typeof Base2' is not a constructor function type.
Or super should not be inferred as any.

Actual behavior:

No error and super: any

Related Issues:

Code

class Base {
    prop = 1;
}

class Base2 {
    other = 1;
}

const base = Boolean() ? Base : Base2;

class Derived extends base { // ExpressionWithTypeArguments is inferred as 'any', expected error "Type 'typeof Base | typeof Base2' is not a constructor function type."
    static fn() {
        super.wargarbl.wat; // super is inferred as 'any'
    }
    fn() {
        super.wargarbl.wat; // super is inferred as 'any'
    }
}
Compiler Options
{
  "compilerOptions": {
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,
    "strictBindCallApply": true,
    "noImplicitThis": true,
    "noImplicitReturns": true,
    "alwaysStrict": true,
    "esModuleInterop": true,
    "declaration": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "moduleResolution": 2,
    "target": "ES2017",
    "jsx": "React",
    "module": "ESNext"
  }
}

Playground Link: Provided

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the TypeScript code example and its provided Playground link, comparing the reported behavior between versions 3.6.3, 3.7, and 4.2.0-dev. Reproduce the missing diagnostic for class Derived extends base and verify that the incompatible constructor union is rejected without inferring super as any.

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
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.