-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve function argument type inference #11440
Comments
Personally, I think this would be confusing. I would suggest the following: // module1.ts
export function doOperation(
options: string,
callback: (argument: OperationCallbackArgument) => any
) { ... }
export interface OperationCallbackArgument {
prop1: number,
prop2: string,
prop3: SomeComplexInterface
}
// module 2
import {doOperation, OperationCallbackArgument} from "./module1"
doOperation("options", operationCallback);
function operationCallback(argument: OperationCallbackArgument) {
console.log(argument.prop1);
} Long term, I think the language service will provide refactorings, such as "introduce local function". |
Almost impossible in TypeScript, given current architecture. What you ask for is global type inference: feed type information back to define site from use site. That's what TypeScript is designed to do. Try flowtype for similar feature (but that's not global inference either, flow just infers the argument type from function body) |
duplicate of #15114? |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
Consider the example:
I suggest to improve type inference of
operationCallback
's arguments in this way:What do you think about it?
The text was updated successfully, but these errors were encountered: