TypeScript
TypeScript copied to clipboard
TS18030: An optional chain cannot contain private identifiers
Bug Report
🔎 Search Terms
TS18030
🕗 Version & Regression Information
v4.1.3
- This is a crash
- This changed between versions ______ and _______
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
- I was unable to test this on prior versions because _______
⏯ Playground Link
Playground link with relevant code
💻 Code
class A {
#p = 1;
m (a? :A) {
return a?.#p;
}
}
🙁 Actual behavior
TS18030
🙂 Expected behavior
no error
When this was implemented, it was the behavior described by the spec. That's because optional chaining and private named instance fields were spec'ed in parallel and therefore couldn't reference each other's syntax.
The whole thing is discussed in https://github.com/tc39/proposal-optional-chaining/issues/28 The stage 3 proposal for class fields added this syntax in https://github.com/tc39/proposal-class-fields/pull/301
I have opened a PR to fix this, it is #60263