sindresorhus/eslint-plugin-unicorn

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

Open

#1 112 ouverte le 18 févr. 2021

Voir sur GitHub
 (1 commentaire) (1 réaction) (0 assignés)JavaScript (5 022 stars) (468 forks)user submission
bughelp wanted

Description

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

Guide contributeur