承接 kestrelwp/docblock-typescript-transformer 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

kestrelwp/docblock-typescript-transformer

Composer 安装命令:

composer require kestrelwp/docblock-typescript-transformer

包简介

Transform PHP class DocBlocks to TypeScript types.

README 文档

README

A package to transform PHP DocBlock class property annotations to TypeScript interfaces.

Provides a transformer for the Spatie TypeScript Transformer package.

Usage

use Kestrel\DocblockTypescriptTransformer\Transformers\ClassDocBlockTransformer; use Spatie\TypeScriptTransformer\TypeScriptTransformer; use Spatie\TypeScriptTransformer\TypeScriptTransformerConfig; $transformerConfig = TypeScriptTransformerConfig::create() ->transformers( [ ClassDocBlockTransformer::create(), // ... other transformers ] ) $transformer = TypeScriptTransformer::create( $transformerConfig );

In a PHP class, use @property and the @typescript annotations to ensure TypeScript Transformer will generate the correct TypeScript interface.

/**  * Product  *  * @property-read int $id product ID  * @property string $name product name  * @property string $description description  * @property Brand $brand  * @property ProductCategory[] $categories  * @property array<string, mixed> $metadata {@ts-optional}  * @property array<string, mixed> $internal_metadata {@ts-hidden}  * @property array<string, Brand> $brand_map {@ts-record string, Brand}  * @property float $price {@ts-literal number}  *  * @typescript  */ class Product extends Model {}; #[TypeScript] enum Brand : string { case APPLE = 'apple'; case SAMSUNG = 'samsung'; case GOOGLE = 'google'; }; #[TypeScript] enum ProductCategory: string { case PHONE = 'phone'; case TABLET = 'tablet'; case LAPTOP = 'laptop'; case WIDGET = 'widget'; };

Will result in this:

export type Release = { id: number; name: string; description: string; brand: Brand; categories: ProductCategory[]; metadata?: { [key: string]: any }; brand_map: Record<string, Brand> price: number } export type Brand = "apple" | "samsung" | "google"; export type ProductCategory = "phone" | "tablet" | "laptop" | "widget";

Special tags

@ts-optional

Marks the property as optional in TypeScript.

@ts-hidden

Hides the property from the TypeScript interface.

@ts-record

Generates a Record type in TypeScript. The first argument is the key type, the second argument is the value type.

@ts-literal

Generates a literal type in TypeScript. The argument is the literal type, exactly as it should appear in TypeScript.

统计信息

  • 总下载量: 7.61k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 4
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固