Microsoft/TypeScript
Voir sur GitHubTypeScript fails to detect self-reference issue in "Parameter Properties" of constructors
Open
#62 414 ouverte le 8 sept. 2025
BugDomain: check: Control FlowHelp Wanted
Métriques du dépôt
- Stars
- (48 455 stars)
- Métriques de merge PR
- (Merge moyen 6j 17h) (9 PRs mergées en 30 j)
Description
🔎 Search Terms
- private property self reference
- private property self reference constructor
- Parameter Properties constructor self reference
🕗 Version & Regression Information
- This is reproducible at least between v4.9.5 and nightly -- I have not tried earlier versions
⏯ Playground Link
💻 Code
import { join as _f } from 'node:path';
abstract class MyClassBase {
// this will cause issue in g()!
constructor (private f: typeof _f = f) {
}
g (...args: string[]) {
return this.f(...args);
}
/* // this does not work, however
myFun (f: typeof _f = f) {
f();
}*/
}
class NewClass extends MyClassBase {
join (...args: string[]) {
this.g(...args);
}
}
const c = new NewClass();
console.log(c.join('a', 'b', 'c'));
🙁 Actual behavior
TypeScript compiler does not report any errors.
if you copy transpiled JS file and run that with Node.js, you will see
constructor(f = f) {
^
ReferenceError: Cannot access 'f' before initialization
🙂 Expected behavior
TypeScript clearly shows an error, similar to what would have been seen in regular function parameters
Parameter 'f' cannot reference itself.
Additional information about the issue
The issue originated from this -- https://github.com/microsoft/vscode-js-debug-browsers/issues/19, and I just discovered that the issue in the project or TypeScript has never been fixed. If someone at Microsoft could do a favor and ping the maintainer of that repo as well, it will be much appreciated.