-
-
Notifications
You must be signed in to change notification settings - Fork 50
Open
Labels
bugSomething isn't workingSomething isn't working
Description
What happened?
Generics are not properly generated for generic classes, the unkown type is used. This is the class I'm trying to transform, with valid class-level template. I'm using the laravel package.
This is my configuration form command.
$config
->outputDirectory(__DIR__ . '/../../resources/js/types')
->formatter(PrettierFormatter::class)
->transformer(AttributedClassTransformer::class)
->transformer(EnumTransformer::class)
->replaceType(\DateTime::class, 'array{date: string, timezone_type: int, timezone: string}')
->replaceType(\DateTimeImmutable::class, 'array{date: string, timezone_type: int, timezone: string}')
->replaceType(\DateTimeInterface::class, 'array{date: string, timezone_type: int, timezone: string}')
->replaceType(\Illuminate\Http\UploadedFile::class, new TypeScriptIdentifier('File'))
->transformDirectories($appPath)
->extension(new LaravelTypeScriptTransformerExtension())
->writer(new GlobalNamespaceWriter('generated.d.ts'));This is one of the classes I have
<?php
namespace App\Types;
use Spatie\TypeScriptTransformer\Attributes\TypeScript;
/**
* @template T
*/
#[TypeScript]
final class PaginatedResponse
{
public int $offset = 0;
/**
* @param array<T> $data
*/
public function __construct(
public int $page = 1,
public int $pageSize = 25,
public string $orderBy = 'id',
public string $orderDirection = 'DESC',
public array $data = [],
) {
$this->offset = ($page - 1) * $pageSize;
}
}The resulting type is this, without the generic annotation and unkown array
export type PaginatedResponse = {
offset: number;
page: number;
pageSize: number;
orderBy: string;
orderDirection: string;
data: unknown[];
};How to reproduce the bug
Just configuring the laravel package and launching the command
Package Version
3.0.0
PHP Version
8.4.14
Which operating systems does with happen with?
Linux
Notes
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working