aws / jsii

jsii allows code in any language to naturally interact with JavaScript classes. It is the technology that enables the AWS Cloud Development Kit to deliver polyglot libraries from a single codebase!
https://aws.github.io/jsii
Apache License 2.0
2.63k stars 244 forks source link

Typescript's readonly arrays should be allowed #4508

Open lewisdiamond opened 4 months ago

lewisdiamond commented 4 months ago

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