Skip to content

Changing property declaration order causes errorΒ #62606

@ahejlsberg

Description

@ahejlsberg

πŸ”Ž Search Terms

Variance

πŸ•— Version & Regression Information

This is the behavior in every version I tried.

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/JYOwLgpgTgZghgYwgAgCLWANwgEwCpwBGANhADwDKyEAHpCDgM7IDeyhcjEAXMnCAE8A3MhAQA7r34DkAXwB8rALAAoZOuQB6TcgCiUKAHsoyHMEZwADpYhwozcQAsIIZGGddklozahgZOBAIxHZwYMCGIMx2KFAQ2Pa4qhrIjAjOALZwvBQA2gBEHFz5ALrIAGTIefli4qXJGnFwOJHEAhTpEFm8AEq2LSBtlAVFEKUVVQW1pfKqsqqqoJCwiCgAQpwobKMACj68IACuGYTQIvMqS9DwSMgAchLqbLV7hpa8hIaGpPznCyqBYIxZAISKMMCpQyHKBIXjoKBYXAEEjkbabXgbLgAGlEEl4D3EclmKlBUQhgXBoDCERAcIw2HwRFIZDRXAxmxEtXxj0qmJQCmQAF5IdCkCJtHoDMZVEA

πŸ’» Code

interface DerivedTable<S extends { base: any; new: any }> {
    // Error disappears when these property declarations are reversed
    schema: S["base"] & S["new"]
    readonlySchema: Readonly<S["base"] & S["new"]>
}

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; // Error

πŸ™ Actual behavior

Error.

πŸ™‚ Expected behavior

No error.

Additional information about the issue

Investigation of cause here.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: Variance RelationshipsThe issue relates to variance relationships between typesFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions