sindresorhus/eslint-plugin-unicorn

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

Chiusa

#1112 aperta il 18 feb 2021

 (1 commento) (1 reazione) (0 assegnatari)JavaScript (468 fork)user submission
bughelp wanted

Metriche repository

Star
 (5022 stelle)
Metriche merge PR
 (Merge medio 1g 16h) (399 PR mergiate in 30 g)

Descrizione

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

Guida contributor