sindresorhus/eslint-plugin-unicorn

[consistent-destructuring] incorrect fix for ts `in` type guard

Geschlossen

#1.112 geöffnet am 18.02.2021

 (1 Kommentar) (1 Reaktion) (0 zugewiesene Personen)JavaScript (468 Forks)user submission
bughelp wanted

Repository-Metriken

Stars
 (5.022 Sterne)
PR-Merge-Metriken
 (Durchschn. Merge 1T 16h) (399 gemergte PRs in 30 T)

Beschreibung

const { a }: { a: string } & ({ b: number } | { c: number } | {}) = params
const value = 'b' in params ? params.b : 'c' in params ? params.c : null

// incorrect fixed
const { a, b, c }: { a: string } & ({ b: number } | { c: number } | {}) = params
const value = 'b' in params ? b : 'c' in params ? c : null

Reference: https://www.typescriptlang.org/docs/handbook/advanced-types.html#type-guards-and-differentiating-types

The fixed codes is not runnable anymore. Playground

Contributor Guide