Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Forbid unused property renaming in destructuring binding in function …
…types (#41044) * Forbid renaming a propertyin function type parameters * add tests * Remove renaming from declaration output * accept baseline * accept baseline * renew tests (not very right now) * get correct result * update diagnostic text * accept baseline * add declaration emit test * fix declaration emit * fix formatting * revert unnecessary change * accept baseline * extend tests * Revert "revert unnecessary change" This reverts commit 17a29ff. * accept baseline * Rename and refactor potentialAlways... stuff * add non-identifier names * extend check to non-identifier original property names * update diagnostic message * add related span * accept baseline * add symbol-keyed test case * oops? * workaround for unstable test * fix suggested name * add comment about non-identifier property names * simplify isReferenced check * accept baseline * move it one step further
- Loading branch information
Showing
41 changed files
with
1,691 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
tests/baselines/reference/declarationEmitBindingPatterns.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
tests/baselines/reference/destructuringInFunctionType.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
tests/cases/conformance/es6/destructuring/destructuringInFunctionType.ts(12,18): error TS2842: 'b' is an unused renaming of 'a'. Did you intend to use it as a type annotation? | ||
tests/cases/conformance/es6/destructuring/destructuringInFunctionType.ts(12,28): error TS2842: 'a' is an unused renaming of 'b'. Did you intend to use it as a type annotation? | ||
|
||
|
||
==== tests/cases/conformance/es6/destructuring/destructuringInFunctionType.ts (2 errors) ==== | ||
interface a { a } | ||
interface b { b } | ||
interface c { c } | ||
|
||
type T1 = ([a, b, c]); | ||
type F1 = ([a, b, c]) => void; | ||
|
||
type T2 = ({ a }); | ||
type F2 = ({ a }) => void; | ||
|
||
type T3 = ([{ a: b }, { b: a }]); | ||
type F3 = ([{ a: b }, { b: a }]) => void; | ||
~ | ||
!!! error TS2842: 'b' is an unused renaming of 'a'. Did you intend to use it as a type annotation? | ||
!!! related TS2843 tests/cases/conformance/es6/destructuring/destructuringInFunctionType.ts:12:32: We can only write a type for 'a' by adding a type for the entire parameter here. | ||
~ | ||
!!! error TS2842: 'a' is an unused renaming of 'b'. Did you intend to use it as a type annotation? | ||
!!! related TS2843 tests/cases/conformance/es6/destructuring/destructuringInFunctionType.ts:12:32: We can only write a type for 'b' by adding a type for the entire parameter here. | ||
|
||
type T4 = ([{ a: [b, c] }]); | ||
type F4 = ([{ a: [b, c] }]) => void; | ||
|
||
type C1 = new ([{ a: [b, c] }]) => void; | ||
|
||
var v1 = ([a, b, c]) => "hello"; | ||
var v2: ([a, b, c]) => string; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
tests/baselines/reference/excessPropertyCheckWithSpread.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
tests/cases/compiler/excessPropertyCheckWithSpread.ts(1,25): error TS2842: 'number' is an unused renaming of 'a'. Did you intend to use it as a type annotation? | ||
|
||
|
||
==== tests/cases/compiler/excessPropertyCheckWithSpread.ts (1 errors) ==== | ||
declare function f({ a: number }): void | ||
~~~~~~ | ||
!!! error TS2842: 'number' is an unused renaming of 'a'. Did you intend to use it as a type annotation? | ||
!!! related TS2843 tests/cases/compiler/excessPropertyCheckWithSpread.ts:1:33: We can only write a type for 'a' by adding a type for the entire parameter here. | ||
interface I { | ||
readonly n: number; | ||
} | ||
declare let i: I; | ||
f({ a: 1, ...i }); | ||
|
||
interface R { | ||
opt?: number | ||
} | ||
interface L { | ||
opt: string | ||
} | ||
declare let l: L; | ||
declare let r: R; | ||
f({ a: 1, ...l, ...r }); | ||
|
Oops, something went wrong.