Skip to content

3.4.1 breaks backward compatibility for users of ReadonlyArray #30662

Closed
@fkleuver

Description

@fkleuver

When I tried to update aurelia to the latest TypeScript version, intellisense broke left right and center while the build still succeeds. It appears that ReadonlyArray<never> is emitted as readonly never[] in the type definitions, and the current version of VS Code doesn't understand that.

TypeScript Version: 3.4.1

Search Terms: 3.4.1, ReadonlyArray, readonly

Code

This is the source code:

export const PLATFORM = {
  global: {},
  emptyArray: Object.freeze([]),
  emptyObject: Object.freeze({}),
  noop: () => {},
};

Where the emptyArray resolves to ReadonlyArray<never>:
image

This is the generated type definition:

export declare const PLATFORM: {
    global: {};
    emptyArray: readonly never[];
    emptyObject: Readonly<{}>;
    noop: () => void;
};

And this is what code consuming that type definition will see:

image

Repro:

Not sure how to reproduce this on the typescript playground because it relies on cross-package references, so here is a minimal repro here:

git clone git@github.com:fkleuver/ts-readonly-issue.git
cd ts-readonly-issue
npm ci
npm run build

All will succeed. Now, open packages/runtime/src/index.ts and you'll see the problem:
The ReadonlyArray<any> falls back to any, and any properties after seem to disappear.

Expected behavior:
I would expect ReadonlyArray<never> to be emitted as ReadonlyArray<never> in the type definitions.

Actual behavior:

It is emitted as readonly never[].

This breaks backwards compatibility for anyone using ReadonlyArray and building with 3.4.1+, and will force all consumers to use this same version of TypeScript. Which includes VS Code at the moment :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions