spatie/typescript-transformer

Getting Started example leads to Class "MyCLabs\Enum\Enum" does not exist due to missing Composer package

Closed this issue · 1 comments

I am just getting started so I tried the code from https://spatie.be/docs/typescript-transformer/v2/usage/getting-started. When running it, it seems there is a vital Composer package (myclabs/php-enum) missing for the transformer to run.

Here is my script:

<?php

use Spatie\TypeScriptTransformer\Transformers\MyclabsEnumTransformer;
use Spatie\TypeScriptTransformer\TypeScriptTransformerConfig;
use Spatie\TypeScriptTransformer\TypeScriptTransformer;

$config = TypeScriptTransformerConfig::create()
    // path where your PHP classes are
    ->autoDiscoverTypes(__DIR__ . '/../src')
    // list of transformers
    ->transformers([MyclabsEnumTransformer::class])
    // file where TypeScript type definitions will be written
    ->outputFile(__DIR__ . '/generated.d.ts')
;

TypeScriptTransformer::create($config)->transform();

When running it, it throws the following error on the console:

In MyclabsEnumTransformer.php line 18:
                                            
  Class "MyCLabs\Enum\Enum" does not exist 

Installing myclabs/php-enum via Composer fixed the issue. Did I oversaw something important? And yes, I marked at least one class using @typescript.

Yeah the documentation could be a bit more clear on this, since you're using MyclabsEnumTransformer we expect you to have installed myclabs/php-enum since that's what you're going to transform.

I'm gonna leave this for now since v3's docs a re completely rewritten and a lot more clear on that.