- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.1k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue
Milestone
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
leibaleSpoki4
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue