Closed migvill closed 4 years ago
This looks like it was related to the latest release (https://github.com/krisk/Fuse/pull/281/files)
Our team just ran into the same issue. Hard locking our fuse.js version in package.json fixed the issue for us. We're using typescript version 2.7.2 by the way
Previous
"fuse.js": "^3.2.1"
Fixed
"fuse.js": "3.2.1"
Thanks for flagging.
@gatimus wanna take a look?
@migvill what is the version of typescript?
Looks like the solution I came up with for #265 uses Conditional Types which were introduced in TypeScript 2.8. So Fuse will have to require TypeScript 2.8 or (to support 2.7) we can change the definition to:
search(pattern: string, opts?: SearchOpts): (string | T | Fuse.FuseResult<string> | Fuse.FuseResult<T>)[];
which would require type checks after getting to result. Something like:
function isFuseResult<T>(result: any): result is Fuse.FuseResult<T> {
return typeof result === 'object' && result['item'];
}
const results = fuse.search('/* search term */');
for (let i = 0; i < results.length; i++) {
const result = results[i];
if (isFuseResult(result)) {
if (typeof result.item === 'string') {
result.item; // > string (id)
} else {
result.item; // > T
}
} else {
if (typeof result === 'string') {
result; // > string (id)
} else {
result; // > T
}
}
}
Which could get messy fast. Or could return any
:
search(pattern: string, opts?: SearchOpts): any[];
and let the developer assert / cast the type. All 3 options are opinionated.
@migvill what is the version of typescript?
@gatimus Sorry for late reply, typescript 2.6.2
This looks like it was related to the latest release (https://github.com/krisk/Fuse/pull/281/files)
Our team just ran into the same issue. Hard locking our fuse.js version in package.json fixed the issue for us. We're using typescript version 2.7.2 by the way
Previous
"fuse.js": "^3.2.1"
Fixed
"fuse.js": "3.2.1"
@chrisbendel Thanks for the tip, I was able to get my build working by using "fuse.js": "3.3.1"
I know Current version requires TypeScript 2.8, this is because Conditional Types is required to accurately represent fues.js behavior in TypeScript. Need maintainer input on if this desirable or if alternative(s) is acceptable.
I for one see no reason whatsoever not to use TypeScript v3.3 at this point considering by ways of optional compiler flags there isnothing breaking between v2 and v3.
Furthermore any
should be avoided in TypeScript wherever possible. If you're going to use any
you might as well roll back to regular JavaScript since you're losing the very thing TypeScript meant to primarily fix and thus you're going against the core TypeScript mentality.
I'd say this issue can be closed and people who run into this issue should update their TypeScript.
As an aside the given code example a few comments earlier is also ES5 - now this is an opinion but considering you can just set your target to ES5 and your lib in, for example, esnext there is no reason not to use powerful ES6 features like Array.forEach()
and expressed arrow functions (const someFunc = () => someReturnValue
)
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days
@krisk this could be closed if you are ok with saying Fuse requires TypeScript 2.8 or newer (current is 3.8).
I get a webpack compile error when I import Fuse on an Angular project
It seems the Typescript is invalid. Does anyone know how to fix this? Or workaround this issue?