Add --ts-undefined-for-optionals command line option (#8861)

* Add --ts-undefined-for-optionals command line option

# Details

- Fixes #7656
- Added a new `--ts-undefined-for-optionals` command line option for `flatc`.
- If enabled, generated TypeScript code uses `undefined` for optional fields rather than `null`.

* Also add TS generated test files

* Run `sh scripts/clang-format-git.sh`

* also add tests/ts/lalala-options.ts to the repo

* move new tests to tests/ts/optional_values dir

* add tests/ts/optional_values/optional_values_generated.cjs to the repo

* reuse existing optional_scalars.fbs and add new test

* add comma

* sh scripts/clang-format-git.sh

* remove comma

* sh scripts/clang-format-git.sh

* trying things

* sh scripts/clang-format-git.sh

* done

* address feedback

* sh scripts/clang-format-git.sh

* run `sh scripts/clang-format-git.sh`

* remove uneeded `eslint-disable @typescript-eslint/no-namespace` line

---------

Co-authored-by: José Luis Millán <jmillan@aliax.net>
This commit is contained in:
Iñaki Baz Castillo
2026-02-04 13:37:41 +01:00
committed by GitHub
parent 95ff1f1d80
commit 3211f857d1
13 changed files with 1307 additions and 56 deletions

View File

@@ -265,6 +265,9 @@ const static FlatCOption flatc_options[] = {
{"", "python-gen-numpy", "", "Whether to generate numpy helpers."},
{"", "ts-omit-entrypoint", "",
"Omit emission of namespace entrypoint file"},
{"", "ts-undefined-for-optionals", "",
"Whether to generate undefined values instead of null values for missing "
"optional keys"},
{"", "file-names-only", "",
"Print out generated file names without writing to the files"},
{"", "grpc-filename-suffix", "SUFFIX",
@@ -710,6 +713,8 @@ FlatCOptions FlatCompiler::ParseFromCommandLineArguments(int argc,
opts.python_gen_numpy = false;
} else if (arg == "--ts-omit-entrypoint") {
opts.ts_omit_entrypoint = true;
} else if (arg == "--ts-undefined-for-optionals") {
opts.ts_undefined_for_optionals = true;
} else if (arg == "--annotate-sparse-vectors") {
options.annotate_include_vector_contents = false;
} else if (arg == "--annotate") {