Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Types of property 'isOptimistic' are incompatible. Type 'boolean' is not assignable to type 'true' in EntityCollectionServiceBase after upgrade from @ngrx/data v10.1.2 to v11.0.0 #2928

Closed
rob4226 opened this issue Feb 14, 2021 · 8 comments · Fixed by #3020

Comments

@rob4226
Copy link
Contributor

rob4226 commented Feb 14, 2021

Hi,
I just upgraded @ngrx/data from v10.1.2 to v11.0.0 but now in my class that overrides EntityCollectionServiceBase I get a TypeScript compile error:

Types of property 'isOptimistic' are incompatible. Type 'boolean' is not assignable to type 'true'.

I think it has something to do with #2899 and #2906.

Here is my code:

export class UUIDEntityCollectionServiceBase<
  T extends UUIDEntity
> extends EntityCollectionServiceBase<T> {
  constructor(
    public entityName: string,
    private _dataService: UUIDBasedEntityCollectionDataService<T>,
    private _log: LogService,
    serviceElementsFactory: EntityCollectionServiceElementsFactory
  ) {
    super(entityName, serviceElementsFactory);
  }

  /**
   * Overriding the default `EntityCollectionServiceBase#add()` method so I can
   * add a random uuid as the id of the entity being added and automatically
   * update the `dateAdded` and `dateUpdated` fields.
   * @param entity The new entity to be added.
   * @param options Optional options for the entity.
   */
  add(entity: T, options?: EntityActionOptions): Observable<T> {
    entity = {
      ...entity,
      id: this._dataService.generateValidEntityId(),
      dateAdded: Date.now(),
      dateUpdated: Date.now(),
    };
    return super.add(entity, options); // *HERE options has the error: Types of property 'isOptimistic' are incompatible. Type 'boolean' is not assignable to type 'true'.
  }
}

Just as a test to try to get the signatures right, I replaced my overridden code for add() with the add() function code directly from the ngrx/data source code I get another error:

Types of parameters 'options' and 'options' are incompatible.
Type 'EntityActionOptions & { isOptimistic: false; }' is not assignable to type 'Pick<EntityActionOptions, "correlationId" | "mergeStrategy" | "tag" | "error" | "skip"> & { isOptimistic: true; }'.
Type 'EntityActionOptions & { isOptimistic: false; }' is not assignable to type '{ isOptimistic: true; }'.
Types of property 'isOptimistic' are incompatible.
Type 'false' is not assignable to type 'true'.ts(2416)

// ...
// Both `add()` functions are unerlined with the above error.
add(
    entity: Partial<T>,
    options: Omit<EntityActionOptions, 'isOptimistic'> & { isOptimistic: true }
): Observable<T>;
add(entity: T, options?: EntityActionOptions): Observable<T> {
    return this.dispatcher.add(entity, options);
    // return super.add(entity, options); // same error as above line
}
// ...

All I want to do is pass along the optional argument options to the parent function like I did in v10.1.2. How do I clear the error? Thank you!!

// ...
return super.add(entity, options); // *HERE options has the error: Types of property 'isOptimistic' are incompatible. Type 'boolean' is not assignable to type 'true'.
// ...
@brandonroberts
Copy link
Member

@yharaskrik any ideas here? I think we introduced a fix for this already

@yharaskrik
Copy link
Contributor

Oh Hmm good question. What we did was type function such that if isOptimistic is false then it takes Partial, there must be a conflict somewhere, maybe it doesn't work when explicitly passing true since true is the default? I don't think I actually ever tried that case... I'll see if I can find some time today to check out the typings!

yharaskrik added a commit to yharaskrik/platform that referenced this issue May 15, 2021
Additional overload for `.add()` on NgRx Data Service causes issue when passing in `boolean` to `isOptimistic`. Remove overload as it should not be needed. Resolves ngrx#2928
@yharaskrik
Copy link
Contributor

@brandonroberts I loosened up the typings on the add function. @rob4226 I pasted your code into the data-example-app to ensure your passthrough function worked as expected, it seemed too.

@brandonroberts
Copy link
Member

Thanks @yharaskrik!

@yharaskrik
Copy link
Contributor

No problem! Hopefully this doesn't cause any other problems but it shouldn't as the original signature is very open. 🤷‍♂️

brandonroberts pushed a commit that referenced this issue May 15, 2021
Additional overload for `.add()` on NgRx Data Service causes issue when passing in `boolean` to `isOptimistic`. Remove overload as it should not be needed. Resolves #2928
@rob4226
Copy link
Contributor Author

rob4226 commented May 16, 2021

@yharaskrik @brandonroberts Thanks for your help guys!!

@yharaskrik
Copy link
Contributor

You are welcome!

@Emilius449
Copy link

hi,
I just upgraded @ngrx/data from v11 to v12.1.0 and i got the same issue on entity-collection-service-base

add(entity: Partial, options: EntityActionOptions & {
isOptimistic: false;
}): Observable;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants