Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript's readonly arrays should be allowed #4508

Open
lewisdiamond opened this issue May 9, 2024 · 0 comments
Open

Typescript's readonly arrays should be allowed #4508

lewisdiamond opened this issue May 9, 2024 · 0 comments
Labels
feature-request A feature should be added or improved. p1

Comments

@lewisdiamond
Copy link
Member

lewisdiamond commented May 9, 2024

Describe the bug

An interface

export interface Props {
  readonly myArray: readonly string[];
}

fails with =:

src/index.ts:3:17 - error JSII3001: Type "ReadonlyArray" cannot be used as the property type because it is private or @internal

preventing using it as

const arr = ["a","b"] as const

Expected Behavior

It should compile, ReadonlyArray<> is a TS type.

Current Behavior

src/index.ts:3:17 - error JSII3001: Type "ReadonlyArray" cannot be used as the property type because it is private or @internal

Reproduction Steps

export interface Props {
    readonly p: readonly string[];
}

export class C {
    private s: readonly string[];
    constructor(p: Props) {
        this.s = p.p;
    }
    f() {
        return this.s;
    }
}

Possible Solution

Map ReadonlyArray to a plain array in languages not supporting readonly.

Additional Information/Context

No response

SDK version used

latest

Environment details (OS name and version, etc.)

Linux

@lewisdiamond lewisdiamond added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels May 9, 2024
@mrgrain mrgrain added p1 and removed needs-triage This issue or PR still needs to be triaged. labels May 15, 2024
@mrgrain mrgrain added feature-request A feature should be added or improved. and removed bug This issue is a bug. labels Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request A feature should be added or improved. p1
Projects
None yet
Development

No branches or pull requests

2 participants