jsii icon indicating copy to clipboard operation
jsii copied to clipboard

Typescript's readonly arrays should be allowed

Open lewisdiamond opened this issue 9 months ago • 0 comments

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 avatar May 09 '24 17:05 lewisdiamond