Skip to content

Readonly<T> not working #28968

Closed
Closed

Description

@trusktr

TypeScript Version: 3.3.0-dev.20181208

Search Terms:

Readonly

Code

const a: Readonly<number[]> = [1,2,3]
a[1] = 4

Expected behavior:

Should not let me write.

Actual behavior:

It does.

Playground Link:

http://www.typescriptlang.org/play/#src=const%20a%3A%20Readonly%3Cnumber%5B%5D%3E%20%3D%20%5B1%2C2%2C3%5D%0Aa%5B1%5D%20%3D%204%0A

Related Issues:

Activity

  1. added
    SuggestionAn idea for TypeScript
    Needs ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.
    on Dec 11, 2018
  2. trusktr commented on Dec 12, 2018

    @trusktr
    ContributorAuthor

    Wesley Wigham (@weswigham) based on your labels, I suppose this is something that never worked the way I was expecting above?

  3. trusktr commented on Dec 12, 2018

    @trusktr
    ContributorAuthor

    Ah, I didn't know about ReadonlyArray, that works well:

    const a: ReadonlyArray<number[]> = [1,2,3]
    a[1] = 4

    (playground)

  4. AlCalzone commented on Dec 13, 2018

    @AlCalzone
    Contributor

    It should be ReadonlyArray<number> btw :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

FixedA PR has been merged for this issueNeeds ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.SuggestionAn idea for TypeScript

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions