Closed
Description
TypeScript Version: 2.3.4
Code
interface I {
x: number | null;
}
function generic<T extends I>(a: T, b: Partial<T>) {
if (a.x != null) {
a.x.toFixed(2); // OK
}
if (b.x != null) {
b.x.toFixed(2); // ERROR: Property 'toFixed' does not exist on type 'T["x"]'
}
}
function notGeneric(a: I, b: Partial<I>) {
if (a.x != null) {
a.x.toFixed(2); // OK
}
if (b.x != null) {
b.x.toFixed(2); // OK
}
}
Expected behavior:
The mapped generic code should compile without error.
Actual behavior:
The mapped generic code does not compile.
For context, the place I'm seeing this issue is React when interacting with props
. The React typings for a Component
are:
class Component<P, S> {
props: Readonly<{ children?: ReactNode }> & Readonly<P>;
// snip
}