microsoft / microsoft/TypeScript

Type infer issue in interfaces with internal properties

Aperta
#42,716 5 commenti 0 reazioni 1 assegnatario Vedi su GitHub

@rbuckton ci sta già lavorando.

Dal 10/2/2021.

Rescheduled
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

Bug Report

🕗 Version & Regression Information

4.1.3 & 4.2.0-dev the same

⏯ Playground Link

https://www.typescriptlang.org/play?ts=4.2.0-beta#code/JYOwLgpgTgZghgYwgAgEJwM4oN4ChkHKgbAAmEAXMnobcgG5UgCuAtgEbQDc+hAvrgG5QkWIhQANZBAAekEKQxpMOXgWJlK1NXUbIAjDoG04TNpyg9aMgPxmO3QbmHho8JMgCa0uRAVL0LG1aDXIqGjoCPQAmIx1TZBYHSx0ATztE80chETdxZAAtH3lFZSCI9RASMODIhioAZjjaAC8MpIseIQQAeyqwBmj7C2QAXmRongAbCAH6fSp9AB9J52AYZAAKemix0fHogEoGfTGJrmkpoPmz-R5cXv6GOCnmLSklrzOKoirNcJ0tD08yMABp4osAAyCe6PDA9GYAOimPQA5tsXm9DjwgA

💻 Code
interface Base {
    inside: {
        v: number;
    }
}

interface X extends Base {
    inside: {
        v: 1
    }
    a: number;
    x?: number;
}

interface Y extends Base {
    inside: {
        v: 2
    }
    a: number;
    y?: number;
}

interface Z extends Base {
    inside: {
        v: 3
    }
    z?: number;
}

const v2: number = 2;
let v1: 1|2;

if (v2 === 2) v1 = 2; else v1 = 1;

const value: X | Y = {
    inside: {
        v: v1
    },
    a: 10
};

console.log(value);
🙁 Actual behavior

Type '{ inside: { v: 1 | 2; }; a: number; }' is not assignable to type 'X | Y'.
Type '{ inside: { v: 1 | 2; }; a: number; }' is not assignable to type 'Y'.
Types of property 'inside' are incompatible.
Type '{ v: 1 | 2; }' is not assignable to type '{ v: 2; }'.(2322)

🙂 Expected behavior

No error ^^

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.