Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Collection of changes i had to implement get this lib to work with a demo project.
While a
record
might be the correct type when transforming to ts, in practice, nearly everything was a record then. The current change is super dirty and would be better implemented by a "is list" check. But not sure, if the approach is compatible then with 3rd party libraries like LaravelData (thinking about the return type of::collect()
here).::collect()
returned its whole union of return types (e.g.array|DataCollection|PaginatedDataCollection|CursorPaginatedDataCollection|Enumerable|AbstractPaginator|PaginatorContract|AbstractCursorPaginator|CursorPaginatorContract|LazyCollection|Collection
) necessitating the deletion of the count checks. Not sure how we can improve this.The argument of
LiteralTypescriptType
Attributes has to be evaluated explicitly since its argument is a string and not a type. If evaluating it via::transform()
the return type would be the type of a constant string with the argument value. But the argument value itself is needed as a type. Therefor we handle it explicitly. PHPstan should be able to analyze it statically most of the time, since the attribute arguments needs to be literal or a constant expression (see https://www.php.net/manual/en/language.attributes.syntax.php).