Skip to content

Add API to detect wherever a symbol is readonly #63828

Description

Similar to #31296

In Strada, it is roughly possible to reimplement .isReadonlySymbol() using the internal CheckFlags (which is necessary to detect readonly properties in mapped types). That will not work with TypeScript 7.

A solution could be adding .isReadonlySymbol() to the type checker as requested in the above-mentioned issue.

But it feels like APIs to detect wherever a symbol is optional or readonly could be similar. For instance, symbol.flags could be used to check for SymbolFlags.Readonly (similar to SymbolFlags.Optional):

function isOptionalProperty(symbol: ts.Symbol) {
  return !!(symbol.flags & ts.SymbolFlags.Optional);
}

function isReadonlyProperty(symbol: ts.Symbol) {
  return !!(symbol.flags & ts.SymbolFlags.Readonly);
}

Alternatively, those both could be getters: symbol.isOptional, symbol.isReadonly.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions