microsoft / microsoft/TypeScript
"is not a constructor" should be detected in compile time as "used before its declaration."
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 3.2.2
This repository demonstrates that I run in to the issue in ts@next.
https://github.com/qballer/tsbug
Search Terms:
constructor, lexical scope, run time error vs compile time
Code
const b = getB()
function getB() {
// will throw C is not a constructor in runtime
return new C() // **
}
// Will generate: Class 'C' used before its declaration.
// const instanceOfC = new C()
class C {}
Expected behavior:
Should generate: Class 'C' used before its declaration.
Actual behavior:
Explodes in runtime with 'is not a constructor' error.
Playground Link:
Playground
Repo
Related Issues:
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 reproduction code in the linked qballer/tsbug repository and the TypeScript Playground example, then compare the existing diagnostic for const instanceOfC = new C() with the getB() case. Done means the compiler reports "Class 'C' used before its declaration" for the constructor call instead of allowing the runtime "is not a constructor" failure.
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
- Mostly clear
- Newbie friendliness
- 35/100