Skip to content

Readonly has issues with intersection types #21184

Closed
@johnfn

Description

@johnfn

TypeScript Version: 2.6.2

Code

class Foo<T, U> {
    thing(): Readonly<T> {
        return undefined as T;
    }

    erroringThing(): Readonly<T & U> {
        return undefined as T & U; // Type 'T & U' is not assignable to type 'Readonly<T & U>'.
    }
}

Expected behavior:
Both of these are error free.

Actual behavior:

Type 'T & U' is not assignable to type 'Readonly<T & U>'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions