Skip to content

API: expose isReadonlySymbol #31296

Open
Open
@ajafff

Description

@ajafff

Search Terms

readonly symbol property

Suggestion

Expose isReadonlySymbol as a method on TypeChecker.

Currently there's no way to tell for sure if a property is readonly.
While cumbersome userland implementations can check for readonly modifier in Symbol.declarations, if it's a GetAccessor without corresponding SetAccessor or if it originated in Object.definePropery(this, 'propName', {value, writable: false}).

However, there's one more thing: Readonly mapped type only sets Symbol.checkFlags which is internal.

So at the very least I need an API to tell if a property's symbol comes from a mapped type with a readonly modifier.

/cc @CSchulz you probably need the same API for the lint rule you want to develop.

Metadata

Metadata

Assignees

No one assigned

    Labels

    APIRelates to the public API for TypeScriptIn DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions