From 54d10e4519ba7f540e2780d6bee14646dc2db648 Mon Sep 17 00:00:00 2001 From: Enzo Innocenzi Date: Fri, 29 Apr 2022 18:56:05 +0200 Subject: [PATCH] feat: support `nullToOptional` --- config/typescript-transformer.php | 10 +++++++++- src/TypeScriptTransformerServiceProvider.php | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/config/typescript-transformer.php b/config/typescript-transformer.php index e028b38..da8f5db 100644 --- a/config/typescript-transformer.php +++ b/config/typescript-transformer.php @@ -7,7 +7,7 @@ */ 'auto_discover_types' => [ - app_path() + app_path(), ], /* @@ -72,4 +72,12 @@ */ 'transform_to_native_enums' => false, + + /* + * By default, this package will convert PHP nullable properties to TypeScript + * types using a `null` type union. Setting `transform_null_to_optional` will + * make them optional instead. + */ + + 'transform_null_to_optional' => false, ]; diff --git a/src/TypeScriptTransformerServiceProvider.php b/src/TypeScriptTransformerServiceProvider.php index f23bd15..d1d9d08 100644 --- a/src/TypeScriptTransformerServiceProvider.php +++ b/src/TypeScriptTransformerServiceProvider.php @@ -42,6 +42,7 @@ public function register(): void ->writer(config('typescript-transformer.writer', TypeDefinitionWriter::class)) ->formatter(config('typescript-transformer.formatter')) ->transformToNativeEnums(config('typescript-transformer.transform_to_native_enums', false)) + ->nullToOptional(config('typescript-transformer.transform_null_to_optional', false)) ); } }