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

Type mismatched... Expected AggregateRootId found AggregateRootIdType #197

Closed
Parables opened this issue Nov 4, 2022 · 1 comment
Closed

Comments

@Parables
Copy link

Parables commented Nov 4, 2022

This type of mismatch is repeated multiple times.

P.S: I see you are updating the docs, you might want to remove the deprecated stuff too, please. Thanks very much for this amazing library.

<?php

declare(strict_types=1);

namespace EventSauce\EventSourcing;

use Generator;

/**
 * @template AggregateRootIdType of AggregateRootId
+  * This might be the cause of it... not sure why you have it here. IMHO, `AggregateRootId` is just perfect.
 * 
 *
 * @see AggregateRootBehaviour
 */
interface AggregateRoot
{
    /**
-      * @return AggregateRootIdType
+     * @return AggregateRootId

     */
    public function aggregateRootId(): AggregateRootId;

    public function aggregateRootVersion(): int;

    /**
     * @return object[]
     */
    public function releaseEvents(): array;

    /**
-     * @param AggregateRootIdType               $aggregateRootId
+   * @param AggregateRootId              $aggregateRootId

     * @param Generator<int, object, void, int> $events
     */
    public static function reconstituteFromEvents(AggregateRootId $aggregateRootId, Generator $events): static;
}
@asgrim
Copy link
Contributor

asgrim commented Jan 22, 2023

@Parables this is template, which makes AggregateRoot a generic; implementors of AggregateRoot should fill in the type (which must be of type AggregateRootId), such that:

final class MyGreatAggregateRootId implements AggregateRootId { /* ... */ }

/** @template-implements AggregateRoot<MyGreatAggregateRootId> */
final class MyGreatAggregateRoot implements AggregateRoot

By doing this, you are telling static analysers (such as PHPStan, Psalm, etc.) that the AggregateRootIdType for your implementation is a MyGreatAggregateRootId (which is a specific implementation of `AggregateRootId).

You can read more about this sort of thing here: https://psalm.dev/docs/annotating_code/templated_annotations/#template-inheritance and https://phpstan.org/blog/generics-by-examples#specify-template-type-variable-of-a-generic-interface-when-implementing-it

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

No branches or pull requests

2 participants