-
-
Notifications
You must be signed in to change notification settings - Fork 208
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
Bug with typescript transformation of Illuminate\Support\Collection
in v4.4.1
#719
Comments
Illuminate\Support\Collection
in v4.4.1
Mmm, it can technically be both because the collection can have keys, if those keys are not sequential (eg export type FooData = {
collection?: Array<App.Data.SomeData> | Record<int, App.Data.SomeData>;
};
}; But I agree, if the collection is keyed with int, it's much better DX to say it should be an array because that's what it's going to be in 99.9999% cases and in the case it's not we can just say |
Did you try with /** @var Collection<SomeData> */ |
Yes, but this results in a PHPStan error, see the last paragraph of the bug report. |
Is a bug indeed, fixed in the next version. |
I think this commit 66e2510 introduced a bug.
Example:
Before v.4.4.1 this would result in the Typescript Type:
Now it results in a record type something like this:
which is not correct because it still gets serialized to an Array by Laravel-data in the end of the day.
This then leads to many wrongly caused type errors.
Also note that using
Collection<SomeData>
as the phpdoc type is not the solution imo, because then PHPStan errors that it expects two generic parametersTKey
andTValue
.The text was updated successfully, but these errors were encountered: