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

ArrayShapes #68

Open
puggan opened this issue Dec 4, 2023 · 3 comments
Open

ArrayShapes #68

puggan opened this issue Dec 4, 2023 · 3 comments

Comments

@puggan
Copy link

puggan commented Dec 4, 2023

phpdocs with arrayshapes fails.

for exemple: /** @var array{a: int[], b: string[], c: float} $config **/

first it fails at the regexp:

return '/@var ((?:\s?[\\w?|\\\\<>,-]+(?:\[])?)+)/';

then it fails at transpiling (phpDocumentor\Reflection\PseudoTypes\ArrayShape)

default => throw new Exception("Could not transform type: {$type}")

it's partly solved with:

$type instanceof PseudoType => $this->execute($type->underlyingType()),

Senario 1

Input: /** @var array<string, array{a: int[], b: string[], c: float}> $config **/

Expected: {[key: string]: {a: number[], b: string[], c: number}}

Current: RuntimeException Unexpected token "", expected '>' at offset 19 on line 1,
due to the regexp only catching @var array<string, array

@rubenvanassche
Copy link
Member

Yeah, this is something we're going to handle in v3 which is next big thing I'm working on, it is scomplete rewrite of TS transformer using PHPStan for those things instead of phpDocumentor.

@spatie-bot
Copy link

Dear contributor,

because this issue seems to be inactive for quite some time now, I've automatically closed it. If you feel this issue deserves some attention from my human colleagues feel free to reopen it.

@puggan
Copy link
Author

puggan commented Oct 9, 2024

Could you update the thrown exception to include what class it failed to parse?

as a workaround i put an echo $class->name, PHP_EOL;
in \Spatie\TypeScriptTransformer\Actions\ResolveTypesCollectionAction::resolveTransformedType
to find out what file I needed to add an #[LiteralTypeScriptType()] in.

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

No branches or pull requests

3 participants