Skip to content

Commit

Permalink
feat: add 1049, 1051, 1052, 1053
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsonk committed Aug 31, 2023
1 parent a7b4e79 commit 224557f
Show file tree
Hide file tree
Showing 15 changed files with 283 additions and 8 deletions.
20 changes: 19 additions & 1 deletion db/1049.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,23 @@
"codeText": "TS1049",
"title": "A 'set' accessor must have exactly one parameter.",
"category": "error",
"documentation": ""
"documentation": "Since setter functions are called when assignment occurs, they can only accept\none value to set, so the following errors:\n\n```ts\nclass A {\n set value(a: number, b: number) {}\n}\n```\n",
"tags": [
"accessors"
],
"related": [
1051,
1052,
1053
],
"fixes": [
{
"title": "Remove extra parameters.",
"body": "Remove any extra parameters:\n\n```ts\nclass A {\n set value(a: number) {}\n}\n```\n"
},
{
"title": "Utilize a tuple.",
"body": "Utilize a tuple to combine values in a single parameter:\n\n```ts\nclass A {\n set value([a, b]: [number, number]) {}\n}\n```\n"
}
]
}
16 changes: 15 additions & 1 deletion db/1051.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,19 @@
"codeText": "TS1051",
"title": "A 'set' accessor cannot have an optional parameter.",
"category": "error",
"documentation": ""
"documentation": "A set accessor is only called when a value is being assigned and will always\nprovide a single value, which cannot be optional. Therefore the following is\ninvalid:\n\n```ts\nclass A {\n set value(a?: number) {}\n}\n```\n",
"tags": [
"accessors"
],
"related": [
1049,
1052,
1053
],
"fixes": [
{
"title": "Remove the optional token.",
"body": "Remove the `?` token:\n\n```ts\nclass A {\n set value(a: number) {}\n}\n```\n\nIf you want to be able to be able to set the property to `undefined`, explicitly\nadd it to the type annotation:\n\n```ts\nclass A {\n set value(a: number | undefined) {}\n}\n```\n"
}
]
}
16 changes: 15 additions & 1 deletion db/1052.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,19 @@
"codeText": "TS1052",
"title": "A 'set' accessor parameter cannot have an initializer.",
"category": "error",
"documentation": ""
"documentation": "A set accessor is only called when a value is being assigned and will always\nprovide a single value, which cannot be optional. Therefore the following is\ninvalid:\n\n```ts\nclass A {\n set value(a = 0) {}\n}\n```\n",
"tags": [
"accessors"
],
"related": [
1049,
1051,
1053
],
"fixes": [
{
"title": "Remove the initializer.",
"body": "Remove the initializer:\n\n```ts\nclass A {\n set value(a: number) {}\n}\n```\n\nIf you want to be able to be able to have a default value when the property is\nset to `undefined`, add `undefined` to the type annotation and handle the\nbehavior in the implementation:\n\n```ts\nclass A {\n #a = 0;\n\n set value(a: number | undefined) {\n this.#a = a ?? 0;\n }\n}\n```\n"
}
]
}
16 changes: 15 additions & 1 deletion db/1053.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,19 @@
"codeText": "TS1053",
"title": "A 'set' accessor cannot have rest parameter.",
"category": "error",
"documentation": ""
"documentation": "Set accessors only ever receive a single value when invoked, therefore a\nvariable number of arguments is not valid:\n\n```ts\nclass A {\n set value(...a: number[]) {}\n}\n```\n",
"tags": [
"accessors"
],
"related": [
1049,
1051,
1052
],
"fixes": [
{
"title": "Remove the rest token.",
"body": "Remove the rest token (`...`):\n\n```ts\nclass A {\n set value(a: number) {}\n}\n```\n\nIf you are trying to accept multiple values, just use an array in the type\nannotation:\n\n```ts\nclass A {\n set value(a: number[]) {}\n}\n```\n"
}
]
}
68 changes: 64 additions & 4 deletions db/_all.json
Original file line number Diff line number Diff line change
Expand Up @@ -607,28 +607,88 @@
"codeText": "TS1049",
"title": "A 'set' accessor must have exactly one parameter.",
"category": "error",
"documentation": ""
"documentation": "Since setter functions are called when assignment occurs, they can only accept\none value to set, so the following errors:\n\n```ts\nclass A {\n set value(a: number, b: number) {}\n}\n```\n",
"tags": [
"accessors"
],
"related": [
1051,
1052,
1053
],
"fixes": [
{
"title": "Remove extra parameters.",
"body": "Remove any extra parameters:\n\n```ts\nclass A {\n set value(a: number) {}\n}\n```\n"
},
{
"title": "Utilize a tuple.",
"body": "Utilize a tuple to combine values in a single parameter:\n\n```ts\nclass A {\n set value([a, b]: [number, number]) {}\n}\n```\n"
}
]
},
{
"code": 1051,
"codeText": "TS1051",
"title": "A 'set' accessor cannot have an optional parameter.",
"category": "error",
"documentation": ""
"documentation": "A set accessor is only called when a value is being assigned and will always\nprovide a single value, which cannot be optional. Therefore the following is\ninvalid:\n\n```ts\nclass A {\n set value(a?: number) {}\n}\n```\n",
"tags": [
"accessors"
],
"related": [
1049,
1052,
1053
],
"fixes": [
{
"title": "Remove the optional token.",
"body": "Remove the `?` token:\n\n```ts\nclass A {\n set value(a: number) {}\n}\n```\n\nIf you want to be able to be able to set the property to `undefined`, explicitly\nadd it to the type annotation:\n\n```ts\nclass A {\n set value(a: number | undefined) {}\n}\n```\n"
}
]
},
{
"code": 1052,
"codeText": "TS1052",
"title": "A 'set' accessor parameter cannot have an initializer.",
"category": "error",
"documentation": ""
"documentation": "A set accessor is only called when a value is being assigned and will always\nprovide a single value, which cannot be optional. Therefore the following is\ninvalid:\n\n```ts\nclass A {\n set value(a = 0) {}\n}\n```\n",
"tags": [
"accessors"
],
"related": [
1049,
1051,
1053
],
"fixes": [
{
"title": "Remove the initializer.",
"body": "Remove the initializer:\n\n```ts\nclass A {\n set value(a: number) {}\n}\n```\n\nIf you want to be able to be able to have a default value when the property is\nset to `undefined`, add `undefined` to the type annotation and handle the\nbehavior in the implementation:\n\n```ts\nclass A {\n #a = 0;\n\n set value(a: number | undefined) {\n this.#a = a ?? 0;\n }\n}\n```\n"
}
]
},
{
"code": 1053,
"codeText": "TS1053",
"title": "A 'set' accessor cannot have rest parameter.",
"category": "error",
"documentation": ""
"documentation": "Set accessors only ever receive a single value when invoked, therefore a\nvariable number of arguments is not valid:\n\n```ts\nclass A {\n set value(...a: number[]) {}\n}\n```\n",
"tags": [
"accessors"
],
"related": [
1049,
1051,
1052
],
"fixes": [
{
"title": "Remove the rest token.",
"body": "Remove the rest token (`...`):\n\n```ts\nclass A {\n set value(a: number) {}\n}\n```\n\nIf you are trying to accept multiple values, just use an array in the type\nannotation:\n\n```ts\nclass A {\n set value(a: number[]) {}\n}\n```\n"
}
]
},
{
"code": 1054,
Expand Down
6 changes: 6 additions & 0 deletions db/_tags.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@
1003,
1002
],
"accessors": [
1051,
1049,
1052,
1053
],
"trailing-comma": [
1009
],
Expand Down
15 changes: 15 additions & 0 deletions docs/1049.md
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) {}
}
```
11 changes: 11 additions & 0 deletions docs/1049_fix_01.md
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) {}
}
```
11 changes: 11 additions & 0 deletions docs/1049_fix_02.md
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]) {}
}
```
16 changes: 16 additions & 0 deletions docs/1051.md
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) {}
}
```
20 changes: 20 additions & 0 deletions docs/1051_fix_01.md
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) {}
}
```
16 changes: 16 additions & 0 deletions docs/1052.md
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) {}
}
```
25 changes: 25 additions & 0 deletions docs/1052_fix_01.md
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;
}
}
```
15 changes: 15 additions & 0 deletions docs/1053.md
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[]) {}
}
```
20 changes: 20 additions & 0 deletions docs/1053_fix_01.md
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[]) {}
}
```

0 comments on commit 224557f

Please sign in to comment.