Skip to content

Forbid unused property renaming in destructuring binding in function types#41044

Merged
andrewbranch merged 31 commits intomicrosoft:mainfrom
uhyo:fix-37454
Jun 14, 2022
Merged

Forbid unused property renaming in destructuring binding in function types#41044
andrewbranch merged 31 commits intomicrosoft:mainfrom
uhyo:fix-37454

Conversation

@uhyo
Copy link
Contributor

@uhyo uhyo commented Oct 11, 2020

Happy hacktoberfest!! 🎃🥳

Fixes #37454.

The PR implements mainly two things, as suggested in #41044 (comment):

  • Emit an error for property renaming in destructing binding in function types if it is unused. This is not under noUnusedLocals nor noUnusedParameters, but declaration files are not checked.
  • Changes declaration emit so that property renaming in destructing bunding is removed if it is unused.

Example

type O = { a?: string; b: number; c: number; };
type F1 = (arg: number) => any; // OK
type F2 = ({ a: string }: O) => any; // Error
type F3 = ({ a: string, b, c }: O) => any; // Error
type F4 = ({ a: string }: O) => any; // Error
type F5 = ({ a: string, b, c }: O) => any; // Error
type F6 = ({ a: string }) => typeof string; // OK
type F7 = ({ a: string, b: number }) => typeof number; // Error
type F8 = ({ a, b: number }) => typeof number; // OK
type F9 = ([a, b, c]) => void; // Error

type G1 = (arg: number) => any; // OK
type G2 = ({ a: string }: O) => any; // Error
type G3 = ({ a: string, b, c }: O) => any; // Error
type G4 = ({ a: string }: O) => any; // Error
type G5 = ({ a: string, b, c }: O) => any; // Error
type G6 = ({ a: string }) => typeof string; // OK
type G7 = ({ a: string, b: number }) => typeof number; // Error
type G8 = ({ a, b: number }) => typeof number; // OK
type G9 = ([a, b, c]) => void; // Error

Results

All the errors below are new in this PR.

src/index.ts:3:17 - error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object?

3 type F2 = ({ a: string }: O) => any; // Error
                  ~~~~~~

src/index.ts:4:17 - error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object?

4 type F3 = ({ a: string, b, c }: O) => any; // Error
                  ~~~~~~

src/index.ts:5:17 - error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object?

5 type F4 = ({ a: string }: O) => any; // Error
                  ~~~~~~

src/index.ts:6:17 - error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object?

6 type F5 = ({ a: string, b, c }: O) => any; // Error
                  ~~~~~~

src/index.ts:8:17 - error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object?

8 type F7 = ({ a: string, b: number }) => typeof number; // Error
                  ~~~~~~

src/index.ts:13:17 - error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object?

13 type G2 = ({ a: string }: O) => any; // Error
                   ~~~~~~

src/index.ts:14:17 - error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object?

14 type G3 = ({ a: string, b, c }: O) => any; // Error
                   ~~~~~~

src/index.ts:15:17 - error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object?

15 type G4 = ({ a: string }: O) => any; // Error
                   ~~~~~~

src/index.ts:16:17 - error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object?

16 type G5 = ({ a: string, b, c }: O) => any; // Error
                   ~~~~~~

src/index.ts:18:17 - error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object?

18 type G7 = ({ a: string, b: number }) => typeof number; // Error
                   ~~~~~~


Found 10 errors in the same file, starting at: src/index.ts:3

Loading
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Breaking Change Would introduce errors in existing code For Backlog Bug PRs that fix a backlog bug

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

didn't have wran message when use bad syntax

8 participants