You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think it makes sense to not add any to inline functions and it's better to leave them for TS to manually infer. It makes migration a bit easier and safer. Example:
// utils.ts =< TS file
function addOne(input: number): number {
return input + 1;
}
// foo.js
function f(input) {
input.map(x => addOne(x))
}
### after ts-migrate runs (foo.ts)
function f(input: any) {
input.map((x: any) => addOne(x)); // <= I want to keep x implicit
}
// when I type `input` I don't get error on the inline
function g(input: string[]) {
input.map((x: any) => addOne(x)); // no error
}
// What I want: adding types to f will infer correctly and detect an error
function f(input: string[]) {
input.map(x => addOne(x)); // Argument of type 'string' is not assignable to parameter of type 'number'.(2345)
}
The text was updated successfully, but these errors were encountered:
You're correct that this is a little annoying when you do decide to add the : string[] annotation and the annotation for the map callback becomes unnecessary.
I'm not sure of the best way to solve this, though. It would be nice if the TypeScript compiler could report unnecessary annotations, maybe.
I think it makes sense to not add
any
to inline functions and it's better to leave them for TS to manually infer. It makes migration a bit easier and safer. Example:The text was updated successfully, but these errors were encountered: