A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/microsoft/TypeScript/issues/38845 below:

Generic inference different between equivalent function expression and arrow function expression in object literal · Issue #38845 · microsoft/TypeScript · GitHub

TypeScript Version: Nightly

Search Terms: parameter, inference, generic, function expression, arrow function expression

Expected behavior:

In function b, parameter a should be inferred as a: () => 42.

Actual behavior:

When using function expression instead of arrow function expression, parameter a is inferred as a: unknown.

Related Issues: #32230

Code

export declare function foo<A>(
    options: {
        a: A
        b: (a: A) => void;
    }
): void;

foo(
    {
        a: () => { return 42 },
        b(a) {}, // a: () => 42
    }    
);

foo(
    {
        a: function () { return 42 },
        b(a) {}, // a: unknown
    }    
);

foo(
    {
        a() { return 42 },
        b(a) {}, // a: unknown
    }    
);
Output
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
foo({
    a: () => { return 42; },
    b(a) { },
});
foo({
    a: function () { return 42; },
    b(a) { },
});
foo({
    a() { return 42; },
    b(a) { },
});
Compiler Options
{
  "compilerOptions": {
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,
    "strictBindCallApply": true,
    "noImplicitThis": true,
    "noImplicitReturns": true,
    "useDefineForClassFields": false,
    "alwaysStrict": true,
    "allowUnreachableCode": false,
    "allowUnusedLabels": false,
    "downlevelIteration": false,
    "noEmitHelpers": false,
    "noLib": false,
    "noStrictGenericChecks": false,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "esModuleInterop": true,
    "preserveConstEnums": false,
    "removeComments": false,
    "skipLibCheck": false,
    "checkJs": false,
    "allowJs": false,
    "declaration": true,
    "experimentalDecorators": false,
    "emitDecoratorMetadata": false,
    "target": "ES2017",
    "module": "ESNext"
  }
}

Playground Link: Provided


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4