For fun, I wanted to try to see how well TypeScript 2.1 could model Svelte's component API.
interface Options<Data, Computed> {
data?: Data
computed?: Computed;
}
declare class Component<Data, Computed> {
constructor(options: Options<Data, Computed>);
get<K extends keyof (Data & Computed)>(key: K): (Data & Computed)[K];
}
let c = new Component({
data: {
hello: ""
}
});
c.get("hello");
// ~~~~~~~ error! '"hello"' is not assignable to type 'never'
Expected: No error.
Actual: The constaint of K on get appears to be 'never', and thus gives an error when calling c.get with any string.
For fun, I wanted to try to see how well TypeScript 2.1 could model Svelte's component API.
Expected: No error.
Actual: The constaint of
Kongetappears to be 'never', and thus gives an error when callingc.getwith any string.