sindresorhus/eslint-plugin-unicorn

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

Closed

#1,112 opened on Feb 18, 2021

 (1 comment) (1 reaction) (0 assignees)JavaScript (468 forks)user submission
bughelp wanted

Repository metrics

Stars
 (5,022 stars)
PR merge metrics
 (Avg merge 1d 16h) (399 merged PRs in 30d)

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