Closed
Description
TypeScript Version: 3.0.1-insiders.20180726 (typescript playground version)
Search Terms:
generic, inference
Code
Note: noImplicitAny
set to true
class BaseClass<P = any> {
public props: P;
}
function w<W extends BaseClass>(
ctr: (new () => W),
props: W['props']
) { }
interface MyClassProps {
myFunc(options: { foo: string }): void;
}
class MyClass extends BaseClass<MyClassProps> {}
// eplicit passing the generic
w<MyClass>(MyClass, {
myFunc(options) {
options.foo; // correctly infers prop
options.bar; // correctly errors
}
});
// inferring `myFunc` sig types based on `MyClass` argument
w(MyClass, {
myFunc(options) { // doesn't infer argument type
options.foo;
options.bar;
}
});
Expected behavior:
Expected the argument of the function to be inferred correctly.
Actual behavior:
Doesn't infer the argument type or provide auto complete on the props of the w()
function (does however type check)
Related Issues: Possibly related to #14829?