Skip to content

Commit c7b0083

Browse files
committed
Test widen literal types of parameter properties
1 parent 6a13fda commit c7b0083

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
tests/cases/conformance/types/literal/literalTypesWidenInParameterPosition.ts(4,9): error TS2322: Type '5' is not assignable to type '1'.
2+
3+
4+
==== tests/cases/conformance/types/literal/literalTypesWidenInParameterPosition.ts (1 errors) ====
5+
class D {
6+
readonly noWiden = 1
7+
constructor(readonly widen = 2) {
8+
this.noWiden = 5; // error
9+
~~~~~~~~~~~~
10+
!!! error TS2322: Type '5' is not assignable to type '1'.
11+
this.widen = 6; // ok
12+
}
13+
}
14+
new D(7); // ok
15+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//// [literalTypesWidenInParameterPosition.ts]
2+
class D {
3+
readonly noWiden = 1
4+
constructor(readonly widen = 2) {
5+
this.noWiden = 5; // error
6+
this.widen = 6; // ok
7+
}
8+
}
9+
new D(7); // ok
10+
11+
12+
//// [literalTypesWidenInParameterPosition.js]
13+
var D = (function () {
14+
function D(widen) {
15+
if (widen === void 0) { widen = 2; }
16+
this.widen = widen;
17+
this.noWiden = 1;
18+
this.noWiden = 5; // error
19+
this.widen = 6; // ok
20+
}
21+
return D;
22+
}());
23+
new D(7); // ok
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class D {
2+
readonly noWiden = 1
3+
constructor(readonly widen = 2) {
4+
this.noWiden = 5; // error
5+
this.widen = 6; // ok
6+
}
7+
}
8+
new D(7); // ok

0 commit comments

Comments
 (0)