-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixedFix AvailableA PR has been opened for this issueA PR has been opened for this issue
Milestone
Description
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
Metadata
Metadata
Assignees
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixedFix AvailableA PR has been opened for this issueA PR has been opened for this issue