You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix unassignable properties by adding undefined with exactOptionalPropertyTypes (#45032)
* Simple first version
Doesn't cover or test any complicated variations.
* Lots of cases work
Destructuring does not. But
- skipping node_modules and lib.* does.
- call expressions does
- property access, including with private identifiers, does
* Support variable declarations, property assignments, destructuring
As long as it's not nested
* More cleanup
* skip all d.ts, not just node_modules/lib
* Offer a codefix for a lot more cases
* remove incorrect tuple check
* Use getSymbolId instead of converting to string
Co-authored-by: Andrew Branch <[email protected]>
* add test + switch to tracking number symbol ids
* Address PR comments
* Exclude tuples from suggestion
* Better way to get error node
Plus add a check that errorNode is an argument to the call, not the
call's expression.
* fix semicolon lint
* fix another crash
* Simplify: add undefined to all optional propertie
whether or not somebody tried to assign undefined to them in the
erroneous assignment
* remove fix-all
Co-authored-by: Andrew Branch <[email protected]>
Copy file name to clipboardExpand all lines: src/compiler/diagnosticMessages.json
+16Lines changed: 16 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1738,6 +1738,10 @@
1738
1738
"category": "Error",
1739
1739
"code": 2374
1740
1740
},
1741
+
"Type '{0}' is not assignable to type '{1}' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.": {
1742
+
"category": "Error",
1743
+
"code": 2375
1744
+
},
1741
1745
"A 'super' call must be the first statement in the constructor when a class contains initialized properties, parameter properties, or private identifiers.": {
1742
1746
"category": "Error",
1743
1747
"code": 2376
@@ -1750,6 +1754,10 @@
1750
1754
"category": "Error",
1751
1755
"code": 2378
1752
1756
},
1757
+
"Argument of type '{0}' is not assignable to parameter of type '{1}' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.": {
1758
+
"category": "Error",
1759
+
"code": 2379
1760
+
},
1753
1761
"The return type of a 'get' accessor must be assignable to its 'set' accessor type": {
1754
1762
"category": "Error",
1755
1763
"code": 2380
@@ -1874,6 +1882,10 @@
1874
1882
"category": "Error",
1875
1883
"code": 2410
1876
1884
},
1885
+
"Type '{0}' is not assignable to type '{1}' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the type of the target.": {
1886
+
"category": "Error",
1887
+
"code": 2412
1888
+
},
1877
1889
"Property '{0}' of type '{1}' is not assignable to '{2}' index type '{3}'.": {
1878
1890
"category": "Error",
1879
1891
"code": 2411
@@ -7118,6 +7130,10 @@
7118
7130
"category": "Message",
7119
7131
"code": 95168
7120
7132
},
7133
+
"Add 'undefined' to optional property type": {
7134
+
"category": "Message",
7135
+
"code": 95169
7136
+
},
7121
7137
7122
7138
"No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer.": {
0 commit comments