sindresorhus/eslint-plugin-unicorn

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

Open

#1,112 opened on Feb 18, 2021

View on GitHub
 (1 comment) (1 reaction) (0 assignees)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

Contributor guide