Closed
Description
Simplified from @types/moonjs
:
type ConstructorOptions<Data> =
& ComponentOptionsProperties<Data>
& ThisType<Instance<Data>>;
interface ComponentOptionsProperties<Data> {
data: Data;
render(): unknown;
}
interface Instance<Data> {
get<K extends keyof Data>(name: K): unknown;
}
declare var Moon: {
<Data>(options?: ConstructorOptions<Data>): Instance<Data>;
};
const r2 = Moon({
data: { msg: "" },
render() {
const h = (x: unknown) => x
return h(this.get("msg")) // <---- error here
},
})
Expected: No error on this.get("msg")
Actual: "'string' is not assignable to parameter of type 'keyof Data'."
"msg" should get the contextual type "msg", but doesn't. But Inference works correctly, so string
isn't assignable to "msg"
This looks like a pretty standard use of ThisType
to make a Vue-like virtual DOM. I couldn't get the failure to reproduce with the containing call to h
as well as return
.