The current packages I have installed are lodash
and @types/lodash
.
In my code, I am using:
import _ from 'lodash';
function doSomething(): string[] {
const letters = ['c', 'a', 'b'];
return _.orderBy(letters, [null], ['asc']);
}
console.log(doSomething());
However, the line
return _.orderBy(letters, [null], ['asc']);
is causing an error:
Type '(string | number | (<U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[]) | (() => string) | (() => string) | (() => string | undefined) | ((...items: string[]) => number) | ... 25 more ... | { ...; })[]' is not assignable to type 'string[]'.
Type 'string | number | (<U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[]) | (() => string) | (() => string) | (() => string | undefined) | ((...items: string[]) => number) | ... 25 more ... | { ...; }' is not assignable to type 'string'.
Type 'number' is not assignable to type 'string'.
Even though it seems like an array of strings should be returned.
Is there a solution to this issue other than manually casting it to
return _.orderBy(letters, [null], ['asc']) as string[];
? Can we specify the type for the orderBy
function based on the letters
variable?