spatie / typescript-transformer

Transform PHP types to TypeScript
https://docs.spatie.be/typescript-transformer/v2/introduction/
MIT License
263 stars 33 forks source link

ArrayShapes #68

Open puggan opened 9 months ago

puggan commented 9 months ago

phpdocs with arrayshapes fails.

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

first it fails at the regexp: https://github.com/spatie/typescript-transformer/blob/37eda5f0f72cce8008b8b4cf0c802e1d35428812/src/TypeReflectors/PropertyTypeReflector.php#L27

then it fails at transpiling (phpDocumentor\Reflection\PseudoTypes\ArrayShape) https://github.com/spatie/typescript-transformer/blob/af3aca5716adede7dd3300e12447ec08e7131655/src/Actions/TranspileTypeToTypeScriptAction.php#L60

it's partly solved with: https://github.com/spatie/typescript-transformer/blob/37eda5f0f72cce8008b8b4cf0c802e1d35428812/src/Actions/TranspileTypeToTypeScriptAction.php#L61

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 commented 7 months ago

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 commented 2 months ago

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.