Open
Description
π Search Terms
isolated declarations quick fix rename ts2842 ts9007
π Version & Regression Information
- This is the behavior in every version I tried
β― Playground Link
π» Code
export function f() {
return (({a: b}: {a: 0}): void => {})!;
}
π Actual behavior
Quick fix introduces a type error:
export function f(): ({ a: b }: { a: 0; }) => void {
// ~
// 'b' is an unused renaming of 'a'. Did you intend to use it as a type annotation? (2842)
return (({a: b}: {a: 0}): void => {})!;
}
π Expected behavior
export function f(): ({a}: { a: 0; }) => void {
return (({a: b}: {a: 0}): void => {})!;
}
Additional information about the issue
While the quick fix is consistent with the emitted declaration, it ideally wouldn't lead to another type error which can be avoided.
There are cases where it may make sense to preserve the renaming, most obviously
export function f(): ({ a: b }: { a: 0; }) => typeof b {
return (({a: b}: {a: 0}): typeof b => b)!;
}
but also perhaps
export function f() {
return (({a: b}: {a: 0}, a: {}): void => {})!;
}
though, maybe surprisingly, this would currently this still result in ts(2842)
export function f(): ({ a: b }: { a: 0; }, a: {}) => void {
// ~
// 'b' is an unused renaming of 'a'. Did you intend to use it as a type annotation? (2842)
return (({a: b}: {a: 0}, a: {}): void => {})!;
}
Perhaps this could be relaxed. While b
is unused in the direct sense, it technically has value in that it avoids the naming collision between the a
s.