Skip to content

Comments

[TS] Support vectors, numerics, and strings with defaults#8896

Merged
bjornharrtell merged 1 commit intogoogle:masterfrom
abhay-agarwal:fix-typescript-optional-values
Feb 23, 2026
Merged

[TS] Support vectors, numerics, and strings with defaults#8896
bjornharrtell merged 1 commit intogoogle:masterfrom
abhay-agarwal:fix-typescript-optional-values

Conversation

@abhay-agarwal
Copy link
Contributor

@abhay-agarwal abhay-agarwal commented Jan 3, 2026

This PR enables vector, numeric, and string types in typescript to have default values. The method signature for accessing a string now depends on whether the property is either required, or has a default value. In either case, the signature becomes:

name():string
name(optionalEncoding:flatbuffers.Encoding):string|Uint8Array
name(optionalEncoding?:any):string|Uint8Array

instead of

name():string|null
name(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null
name(optionalEncoding?:any):string|Uint8Array|null

For string types, typescript allows you to inline a global/constant, so we just return that if there is no value in the buffer. For vectors, we return a new vector, (I.e. new Float32Array(), etc.), since there is no concept of an "inner" default value for vector types.

One significant finding was that the parser parses optional string type properties with a value of "0", meaning that if a user were to create a string with a default value of "0", then it would parse as nullable. I didn't want to disturb the codebase too much, but changing this would seemingly require some new logic in the parser to handle zero vs null values.

Closes #8888

@github-actions github-actions bot added python c++ javascript typescript codegen Involving generating code from schema labels Jan 3, 2026
@abhay-agarwal abhay-agarwal changed the title Support vectors, numerics, and strings with defaults (closes #8888) Support vectors, numerics, and strings with defaults Jan 3, 2026
@abhay-agarwal abhay-agarwal force-pushed the fix-typescript-optional-values branch from 788c313 to 0ebb35d Compare January 3, 2026 18:28
@abhay-agarwal abhay-agarwal changed the title Support vectors, numerics, and strings with defaults [TS] Support vectors, numerics, and strings with defaults Jan 3, 2026
@abhay-agarwal
Copy link
Contributor Author

Will likely have a merge conflict with #8861

@bjornharrtell
Copy link
Collaborator

@abhay-agarwal this also looks nice, so if we can get #8861 in then feel free to also update this and I'll try to get it in too.

@bjornharrtell bjornharrtell self-requested a review February 4, 2026 15:27
bjornharrtell
bjornharrtell previously approved these changes Feb 4, 2026
@abhay-agarwal
Copy link
Contributor Author

abhay-agarwal commented Feb 17, 2026

Not sure if I understand the codebase well enough, but running the test suite does generate a lot of changed test files. Nevertheless, the test suite does seem to pass locally. @bjornharrtell can you approve the test suite pass?

@jtdavis777
Copy link
Collaborator

@abhay-agarwal looks like you have a merge conflict - do you mind updating this?

@abhay-agarwal
Copy link
Contributor Author

Yup let me take a look tonight!

@abhay-agarwal abhay-agarwal force-pushed the fix-typescript-optional-values branch from ec8f6a4 to 2641c0c Compare February 21, 2026 09:10
@abhay-agarwal
Copy link
Contributor Author

@jtdavis777 done!

@bjornharrtell
Copy link
Collaborator

@abhay-agarwal unfortunately still some test failures to figure out.

@abhay-agarwal abhay-agarwal force-pushed the fix-typescript-optional-values branch 2 times, most recently from 9c62cc0 to 649d26b Compare February 23, 2026 01:53
@github-actions github-actions bot added the c# label Feb 23, 2026
@abhay-agarwal abhay-agarwal force-pushed the fix-typescript-optional-values branch 3 times, most recently from 1e6624f to cfee84e Compare February 23, 2026 01:59
@abhay-agarwal
Copy link
Contributor Author

@bjornharrtell please approve the tests again, I had some rebase issues.

@abhay-agarwal abhay-agarwal force-pushed the fix-typescript-optional-values branch from cfee84e to ef333f8 Compare February 23, 2026 05:53
@abhay-agarwal
Copy link
Contributor Author

hmm, okay I think it should work now?

@bjornharrtell
Copy link
Collaborator

@abhay-agarwal still a few generated code test failures.

…ts are supported

Fixing issues with generated ts/js
@abhay-agarwal abhay-agarwal force-pushed the fix-typescript-optional-values branch from ef333f8 to 76c34b2 Compare February 23, 2026 07:43
@abhay-agarwal
Copy link
Contributor Author

Okay, try now.

Sorry, I'm still a bit confused by how the test suite works!

Copy link
Collaborator

@bjornharrtell bjornharrtell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM and a great contribution, thanks @abhay-agarwal for your efforts and patience.

@bjornharrtell bjornharrtell merged commit 94d6b80 into google:master Feb 23, 2026
51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TS] Support default values for strings

3 participants