Skip to content

Mapped type property causses different assignability error of compatible subtypesΒ #62520

@dragomirtitian

Description

@dragomirtitian

πŸ”Ž Search Terms

assignability mapped type sub type

πŸ•— Version & Regression Information

  • This changed between versions 3.3 and 3.5, but the behavior was not correct in 3.3 either, 3.5 just makes it a bit better but less consistent.

⏯ Playground Link

Playground Link

πŸ’» Code

interface Table<B> { schema: B; }

interface DerivedTable<S extends DerivedSchema<any, any>> extends Table<S["base"] & S["new"]>{
    // readonlySchema: Readonly<S["base"] & S["new"]>
}
type DerivedSchema<B, N> = { base: B; new: N };

interface Base { baseProp: number; }
interface New  { newProp: boolean; }

declare const source: DerivedTable<{ base: Base, new: New }>
const destination: DerivedTable<{ base: Base; new: New & Base }> = source;

πŸ™ Actual behavior

There is an error on the last line

πŸ™‚ Expected behavior

DerivedTable<{ base: Base, new: New }> and DerivedTable<{ base: Base; new: New & Base }> are both equivalent to Table<New & Base> and so the assignment on the last line should succeed. Commenting out the readonlySchema property will actually make the assignment succeed. At the very least this should always be an error as it was in 3.3.

Additional information about the issue

Found while testing tsgo which depending on type order might errors on it even with readonlySchema present. Reported as microsoft/typescript-go#1781

Metadata

Metadata

Assignees

No one assigned

    Labels

    Won't FixThe severity and priority of this issue do not warrant the time or complexity needed to fix it

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions