What is the reason for the absence of errors in this code snippet:
interface X {
a: string;
b?: string;
}
type Y<T> = {
[key in keyof T]: boolean;
}
class A<Definition> {
constructor(public readonly definition: Definition, public readonly fields: Y<Definition>) {
}
}
const y = {
a: true,
c: false
}
const a = new A<X>({a: 'first', b: 'second'}, y)
However, an error arises with this code block?
interface X {
a: string;
b?: string;
}
type Y<T> = {
[key in keyof T]: boolean;
}
const y: Y<X> = {
a: true,
c: false,
}
The goal is to trigger an error similar to the first example due to c
not being a key of X
.
If I include the type Y<X>
for y
in the initial example, a compiler error occurs.