Argument of type 'number | (<U>(callbackfn: (value: Item, index: number, array: Item[]) => U, thisArg?: any) => U[]...' is not assignable to parameter of type 'Item'.
Type 'number' is not assignable to type 'Item'.
The fun thing is if I change Item['value']
type to string
the error goes away.
Versions:
Tested with [email protected] / @2.8.3
@types/[email protected]
Mentions: @bczengel @chrootsu @stepancar @aj-r @Ailrun @e-cloud @thorn0 @jtmthf @DomiR
[@types/lodash] Strange error in _.find
[@types/lodash] _.find
- type number
is not assignable to type 'X'
May 14, 2018
Looks like it's matching the wrong overload. It's supposed to match this:
find<T>(
collection: List<T> | null | undefined,
predicate?: ListIterateeCustom<T, boolean>,
fromIndex?: number
): T|undefined;
However it doesn't due to this error:
Argument of type '{ value: string; }' is not assignable to parameter of type 'string | [string, any] | ListIterator<Item, boolean> | PartialDeep<Item> | undefined'.
Type '{ value: string; }' is not assignable to type 'PartialDeep<Item>'.
Types of property 'value' are incompatible.
Type 'string' is not assignable to type 'PartialDeep<any> | undefined'.
There are a few workarounds - adding value as any
seems to fix the issue:
const found = _.find(this.items, {value: value as any});
or this:
this.selectedItems = _.transform(selected, (items, value: any) => {
const found = _.find(this.items, {value});
if (found) {
// Error (see below)
items.push(found);
}, [] as Item[]);
It should be possible to fix this using conditional types in TS 2.8, but that would require us to drop support for all earlier versions of typescript, which we're not ready to do.
We're using TS2.8 now, so this I think can be fixed by merging the
overloads using conditional types. I can't do that right now, but if
someone submits a PR then I'll review it.
On Tue, Jul 23, 2019, 12:25 AM Edward Chu, ***@***.***> wrote:
This still happens on TS 3.5
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<
#25758?email_source=notifications&email_token=ABVF5M6WEG4O3AQXGINPISDQA2BZ5A5CNFSM4E7VGXA2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2R4GFA#issuecomment-514048788>,
or mute the thread
<
https://github.com/notifications/unsubscribe-auth/ABVF5MYCP5MR7HXSLSI4HYTQA2BZ5ANCNFSM4E7VGXAQ>
Still an issue for me in 2020
export const enhanceStudentSolutionCriteriaGenericRule = <T extends Record>(studentSolution: StudentSolution, allRecords: Array<T>, ruleName: string, recordRefKey = 'name'): StudentSolution => {
const recordsRefs: Array<string> = findByStudentSolutionCriteriaRule(studentSolution, ruleName, [], STRATEGY_DO_NOTHING);
const records: Array<T> = [];
map(recordsRefs, (recordRef: string) => {
records.push(find(allRecords, { [recordRefKey]: recordRef })); // Replace the value (string) by the full entity (object)
});
return updateStudentSolutionCriteriaRule(studentSolution, ruleName, records);
Using as any
fixes it.
records.push(find(allRecords, { [recordRefKey]: recordRef } as any)); // Replace the value (string) by the full entity (object)
Using:
"@types/lodash.find": "4.6.6",
"lodash.find": "4.6.0",
Hi thread, we're moving DefinitelyTyped to use GitHub Discussions for conversations the @types
modules in DefinitelyTyped.
To help with the transition, we're closing all issues which haven't had activity in the last 6 months, which includes this issue. If you think closing this issue is a mistake, please pop into the TypeScript Community Discord and mention the issue in the definitely-typed
channel.
matborowiak, cjvnjde, goldo, sujinleeme, thodwris, bwebs, nia-vf, dmitry-fob, baranelitez, ricalegria, and 13 more reacted with thumbs up emoji
TrySpace reacted with confused emoji
All reactions
Anyone having the error with a similar case as this example:
let key = 'something'
const type:= find(sysTypes, sys => config?.[key])
Coercing to a boolean should solve the error
let key = 'something'
const type:= find(sysTypes, sys => !!config?.[key])