-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
283 additions
and
8 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
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 |
---|---|---|
|
@@ -57,6 +57,12 @@ | |
1003, | ||
1002 | ||
], | ||
"accessors": [ | ||
1051, | ||
1049, | ||
1052, | ||
1053 | ||
], | ||
"trailing-comma": [ | ||
1009 | ||
], | ||
|
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 |
---|---|---|
@@ -1,4 +1,19 @@ | ||
--- | ||
title: "A 'set' accessor must have exactly one parameter." | ||
category: error | ||
tags: | ||
- accessors | ||
related: | ||
- 1051 | ||
- 1052 | ||
- 1053 | ||
--- | ||
|
||
Since setter functions are called when assignment occurs, they can only accept | ||
one value to set, so the following errors: | ||
|
||
```ts | ||
class A { | ||
set value(a: number, b: number) {} | ||
} | ||
``` |
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,11 @@ | ||
--- | ||
title: "Remove extra parameters." | ||
--- | ||
|
||
Remove any extra parameters: | ||
|
||
```ts | ||
class A { | ||
set value(a: number) {} | ||
} | ||
``` |
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,11 @@ | ||
--- | ||
title: "Utilize a tuple." | ||
--- | ||
|
||
Utilize a tuple to combine values in a single parameter: | ||
|
||
```ts | ||
class A { | ||
set value([a, b]: [number, number]) {} | ||
} | ||
``` |
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 |
---|---|---|
@@ -1,4 +1,20 @@ | ||
--- | ||
title: "A 'set' accessor cannot have an optional parameter." | ||
category: error | ||
tags: | ||
- accessors | ||
related: | ||
- 1049 | ||
- 1052 | ||
- 1053 | ||
--- | ||
|
||
A set accessor is only called when a value is being assigned and will always | ||
provide a single value, which cannot be optional. Therefore the following is | ||
invalid: | ||
|
||
```ts | ||
class A { | ||
set value(a?: number) {} | ||
} | ||
``` |
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,20 @@ | ||
--- | ||
title: "Remove the optional token." | ||
--- | ||
|
||
Remove the `?` token: | ||
|
||
```ts | ||
class A { | ||
set value(a: number) {} | ||
} | ||
``` | ||
|
||
If you want to be able to be able to set the property to `undefined`, explicitly | ||
add it to the type annotation: | ||
|
||
```ts | ||
class A { | ||
set value(a: number | undefined) {} | ||
} | ||
``` |
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 |
---|---|---|
@@ -1,4 +1,20 @@ | ||
--- | ||
title: "A 'set' accessor parameter cannot have an initializer." | ||
category: error | ||
tags: | ||
- accessors | ||
related: | ||
- 1049 | ||
- 1051 | ||
- 1053 | ||
--- | ||
|
||
A set accessor is only called when a value is being assigned and will always | ||
provide a single value, which cannot be optional. Therefore the following is | ||
invalid: | ||
|
||
```ts | ||
class A { | ||
set value(a = 0) {} | ||
} | ||
``` |
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,25 @@ | ||
--- | ||
title: "Remove the initializer." | ||
--- | ||
|
||
Remove the initializer: | ||
|
||
```ts | ||
class A { | ||
set value(a: number) {} | ||
} | ||
``` | ||
|
||
If you want to be able to be able to have a default value when the property is | ||
set to `undefined`, add `undefined` to the type annotation and handle the | ||
behavior in the implementation: | ||
|
||
```ts | ||
class A { | ||
#a = 0; | ||
|
||
set value(a: number | undefined) { | ||
this.#a = a ?? 0; | ||
} | ||
} | ||
``` |
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 |
---|---|---|
@@ -1,4 +1,19 @@ | ||
--- | ||
title: "A 'set' accessor cannot have rest parameter." | ||
category: error | ||
tags: | ||
- accessors | ||
related: | ||
- 1049 | ||
- 1051 | ||
- 1052 | ||
--- | ||
|
||
Set accessors only ever receive a single value when invoked, therefore a | ||
variable number of arguments is not valid: | ||
|
||
```ts | ||
class A { | ||
set value(...a: number[]) {} | ||
} | ||
``` |
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,20 @@ | ||
--- | ||
title: "Remove the rest token." | ||
--- | ||
|
||
Remove the rest token (`...`): | ||
|
||
```ts | ||
class A { | ||
set value(a: number) {} | ||
} | ||
``` | ||
|
||
If you are trying to accept multiple values, just use an array in the type | ||
annotation: | ||
|
||
```ts | ||
class A { | ||
set value(a: number[]) {} | ||
} | ||
``` |