I have an Angular/TypeScript application that uses Shippable CI/CD. Everything works great normally but now getting a TS error on Shippable, but not when building locally. (same angular, node, and TS versions both locally and shippable)
The error is
ERROR in src/search.component.ts(81,23): error TS2352: Type 'DataGroup' cannot be converted to type 'DataGroup[]'. Property 'includes' is missing in type 'DataGroup'. src/search.component.ts(83,27): error TS2352: Type 'DataGroup' cannot be converted to type 'DataGroup[]'.
The offending lines are
dataGroups = _.chain(dataGroups)
.filter(dataGroup => !metaDataGroupNames.includes(dataGroup.spreadsheetId))
.sortBy('spreadsheetId')
.value();
metaDataGroups = _.chain(dataGroups)
.filter(dataGroup => metaDataGroupNames.includes(dataGroup.spreadsheetId))
.sortBy('spreadsheetId')
.value();
In the above, dataGroups and metaDataGroups are type DataGroup[]... and filter+sort does indeed return the same.
dataGroups: Array<DataGroup>;
metaDataGroups: Array<DataGroup>;
I tried to cast the result from value with ...value() as DataGroup[];
to no avail.
I also tried to throw everything on a single line like the below incase that was the issue, also to no avail.
this.dataGroups = _.chain(dataGroups).filter(dataGroup => !metaDataGroupNames.includes(dataGroup.spreadsheetId)).sortBy('spreadsheetId').value() as DataGroup[];
this.metaDataGroups = _.chain(dataGroups).filter(dataGroup => metaDataGroupNames.includes(dataGroup.spreadsheetId)).sortBy('spreadsheetId').value() as DataGroup[];
update/workaround
So I never figured out the actual issue but I just broke out the underscore operations into their own statements and the problem went away. Still weird how I was getting the TS error on shippable but not locally, and that it wasn't an error in the first place.
this.dataGroups = _.filter(dataGroups, dataGroup => !metaDataGroupNames.includes(dataGroup.spreadsheetId));
this.dataGroups = _.sortBy(dataGroups, 'spreadsheetId');
this.metaDataGroups = _.filter(dataGroups, dataGroup => metaDataGroupNames.includes(dataGroup.spreadsheetId));
this.metaDataGroups = _.sortBy(dataGroups, 'spreadsheetId');
Hi maybe You could use something like this, I changed the implementation using
some
insteadincludes
: