diff --git a/config/typescript-transformer.php b/config/typescript-transformer.php index f66985b..e96476c 100644 --- a/config/typescript-transformer.php +++ b/config/typescript-transformer.php @@ -7,7 +7,7 @@ */ 'auto_discover_types' => [ - app_path() + app_path(), ], /* @@ -75,4 +75,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 6387e04..289ceee 100644 --- a/src/TypeScriptTransformerServiceProvider.php +++ b/src/TypeScriptTransformerServiceProvider.php @@ -33,6 +33,7 @@ public function packageRegistered(): 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)) ); } }