PVermeer / dexie-addon-suite-monorepo

MIT License
8 stars 0 forks source link

Ref type does not work when passing an array type and using Array.every() #1

Closed PVermeer closed 2 years ago

PVermeer commented 2 years ago

Array.every() Does not work for some reason. All other Array methods work as intended.

https://github.com/PVermeer/dexie-addon-suite-monorepo/blob/a2a3db14353a9f8cc01aa3838969374a2cc2da62/packages/dexie-populate-addon/src/types.ts#L21

Ref<Friend[], number[], "Ref">

https://github.com/PVermeer/dexie-addon-suite-monorepo/blob/2bca9b30c31a703238ac9fd883f844e0bcddfca0/packages/dexie-populate-addon/test/unit-tests/karma/typings.spec.ts#L190-L191

This expression is not callable. Each member of the union type '{ \(predicate: (value: number, index: number, array: number[]) => value is S, thisArg?: any): this is S[]; (predicate: (value: number, index: number, array: number[]) => unknown, thisArg?: any): boolean; } | { ...; }' has signatures, but none of those signatures are compatible with each other. ts(2349)

Disabling this overload type in lib.es5.d.ts fixes the issue:

every<S extends T>(predicate: (value: T, index: number, array: T[]) => value is S, thisArg?: any): this is S[];

https://github.com/microsoft/TypeScript/blob/0019c0190df637901606b7fc6b563b482038a14b/lib/lib.es5.d.ts#L1331

Currently I have no idea how to fix this (maybe TypeScript bug?).

Workaround: use the inverted Array.some() to get the same result.

PVermeer commented 2 years ago

Should be fixed with 69ac66a. Unfortunately with a breaking change.