facebook / facebook/flow

Refinement of polymorphic type does not work

Abierto
#3,679 1 comentario 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Rust
Estrellas
22.3k
Forks
1.9k
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

Refining a type which has a polymorphic subtype doesn't seem to work properly.

Here's the code:

```js
export type InnerTypeA = {
type: "A",
};

export type InnerTypeB = {
type: "B",
};

export type InnerType = InnerTypeA | InnerTypeB;

type OuterType = {
inner: T,
};

export type OuterTypeA = OuterType;
export type OuterTypeB = OuterType;

function test(a: OuterTypeB) {}
function test2(a: OuterType) {}

function b(a: OuterType) {
if (a.inner.type === "B") {
// Doesn't work:
test(a);

// Works, which means the inner refinement is still there
// test({inner: a.inner});

// Works, which means the outer refinement is also there?
// test2(a);
}
}

b({inner:{type:"B"}})
```

[Online Flow-try](https://flow.org/try/#0KYDwDg9gTgLgBDAnmYcCSA7DwoBVnACCcAvHAN4BQcCBAXHAESGMA0lAvgNyWWiSxaKdFhz4UAIVIVqQ4A0YS2nHn3DR4SYZmx4C0nWILEAPiN3jgE1VtQB5AK4wjKADy4GhvSgB80qjQAlqJQDLjs3Lz8GnJwjs7eRNLxLsCuXpaEPjzRgrZxTqlSZCmJ6SGWEtm8AGYOGADGMIEQGAjAAM4wABQAhgyllQCUFByUdY3Nre1dAEzuPn0DhWW4PiPkY+P1TS1tAEbunhUEi-0FCZYLG7KBNXB9AHTBuo-5JB9MSjc0NAD0fzgABEIJ0MAByeAAd2gAGs6LIaM4un0hqpfnAAXAAOpwjqsOBQgAWgQaRLgAFtgL0MB0EETUC8cHAoMAasFgFSMPBAnSuoEADYC+k4YCIzGA5E9chM0JwXrPEIcNHi8VY3FQWH4wkksmU6m0kVwCArFlsjlcnl03oCjoQEWsgD8aslnRgs1RPBoYy2+26MpCdHItjoikYHGVQA).

This doesn't seem to be expected "pessimistic refinement" behaviour, since no other function calls happen between the guard and the type check.

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.