TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

TS18030: An optional chain cannot contain private identifiers

Open LongTengDao opened this issue 4 years ago • 2 comments

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

LongTengDao avatar Feb 10 '21 08:02 LongTengDao

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

ajafff avatar Feb 10 '21 09:02 ajafff

I have opened a PR to fix this, it is #60263

Psychpsyo avatar Oct 17 '24 21:10 Psychpsyo