Closed
Description
TypeScript Version: 4.0.0-dev.20200516
Search Terms: object literal inference arrow function method
Expected behavior: M
in inferred as { foo: () => void; }
Actual behavior:: When using function
or method syntax M
is inferred as unknown
. Using arrow functions works fine.
Related Issues: #32230 But that specific case seems fixed
Code
function make<M>(o: { mutations: M, action: (m: M) => void }) { }
make({
mutations: {
foo () { } // Nope
// foo: function () { } // Nope
// foo: () => { } // OK
},
action: (a) => { a.foo() }
})
Output
"use strict";
function make(o) { }
make({
mutations: {
// foo () { } // Nope
// foo: function () { } // Nope
foo: () => { } // OK
},
action: (a) => { a.foo(); }
});
Compiler Options
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"strictBindCallApply": true,
"noImplicitThis": true,
"noImplicitReturns": true,
"alwaysStrict": true,
"esModuleInterop": true,
"declaration": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"moduleResolution": 2,
"target": "ES2017",
"jsx": "React",
"module": "ESNext"
}
}
Playground Link: Provided