Skip to content

Commit 6cd7454

Browse files
committed
Add tests
1 parent f58e1a2 commit 6cd7454

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

tests/cases/conformance/types/mapped/mappedTypeErrors.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,9 @@ c.setState({ });
125125
c.setState(foo);
126126
c.setState({ a: undefined }); // Error
127127
c.setState({ c: true }); // Error
128+
129+
type T2 = { a?: number, [key: string]: any };
130+
131+
let x1: T2 = { a: 'no' }; // Error
132+
let x2: Partial<T2> = { a: 'no' }; // Error
133+
let x3: { [P in keyof T2]: T2[P]} = { a: 'no' }; // Error

tests/cases/conformance/types/mapped/mappedTypeModifiers.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// @strictNullChecks: true
2+
// @noimplicitany: true
23

34
type T = { a: number, b: string };
45
type TP = { a?: number, b?: string };
@@ -74,4 +75,26 @@ var b04: Readonly<BP>;
7475
var b04: Partial<Readonly<B>>;
7576
var b04: Readonly<Partial<B>>;
7677
var b04: { [P in keyof BPR]: BPR[P] }
77-
var b04: Pick<BPR, keyof BPR>;
78+
var b04: Pick<BPR, keyof BPR>;
79+
80+
type Foo = { prop: number, [x: string]: number };
81+
82+
function f1(x: Partial<Foo>) {
83+
x.prop; // ok
84+
(x["other"] || 0).toFixed();
85+
}
86+
87+
function f2(x: Readonly<Foo>) {
88+
x.prop; // ok
89+
x["other"].toFixed();
90+
}
91+
92+
function f3(x: Boxified<Foo>) {
93+
x.prop; // ok
94+
x["other"].x.toFixed();
95+
}
96+
97+
function f4(x: { [P in keyof Foo]: Foo[P] }) {
98+
x.prop; // ok
99+
x["other"].toFixed();
100+
}

0 commit comments

Comments
 (0)