From 067bfdbde9b10c1beb5d6b02d67ae9db8b96f736 Mon Sep 17 00:00:00 2001 From: Jason Date: Sun, 17 Aug 2025 23:19:08 -0400 Subject: [PATCH] Update ts codegen (#8421) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Makes the return type of `static getFullyQualifiedName()` be a string literal instead of just the string type Update tests Co-authored-by: Björn Harrtell --- src/idl_gen_ts.cpp | 8 ++++++-- tests/ts/my-game/example/ability.ts | 2 +- tests/ts/my-game/example/monster.ts | 2 +- tests/ts/my-game/example/referrable.ts | 2 +- tests/ts/my-game/example/stat.ts | 2 +- tests/ts/my-game/example/struct-of-structs-of-structs.ts | 2 +- tests/ts/my-game/example/struct-of-structs.ts | 2 +- tests/ts/my-game/example/test-simple-table-with-enum.ts | 2 +- tests/ts/my-game/example/test.ts | 2 +- tests/ts/my-game/example/type-aliases.ts | 2 +- tests/ts/my-game/example/vec3.ts | 2 +- tests/ts/my-game/example2/monster.ts | 2 +- tests/ts/my-game/in-parent-namespace.ts | 2 +- tests/ts/optional-scalars/scalar-stuff.ts | 2 +- tests/ts/union_vector/attacker.ts | 2 +- tests/ts/union_vector/book-reader.ts | 2 +- tests/ts/union_vector/falling-tub.ts | 2 +- tests/ts/union_vector/hand-fan.ts | 2 +- tests/ts/union_vector/movie.ts | 2 +- tests/ts/union_vector/rapunzel.ts | 2 +- 20 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/idl_gen_ts.cpp b/src/idl_gen_ts.cpp index 234c2be6c..835ba4416 100644 --- a/src/idl_gen_ts.cpp +++ b/src/idl_gen_ts.cpp @@ -1944,11 +1944,15 @@ class TsGenerator : public BaseGenerator { // Emit the fully qualified name if (parser_.opts.generate_name_strings) { + const std::string fullyQualifiedName = struct_def.defined_namespace->GetFullyQualifiedName(struct_def.name); + GenDocComment(code_ptr); - code += "static getFullyQualifiedName():string {\n"; + code += "static getFullyQualifiedName(): \""; + code += fullyQualifiedName; + code += "\" {\n"; code += " return '" + - struct_def.defined_namespace->GetFullyQualifiedName(struct_def.name) + + fullyQualifiedName + "';\n"; code += "}\n\n"; } diff --git a/tests/ts/my-game/example/ability.ts b/tests/ts/my-game/example/ability.ts index e2dadc977..02951cbf2 100644 --- a/tests/ts/my-game/example/ability.ts +++ b/tests/ts/my-game/example/ability.ts @@ -33,7 +33,7 @@ mutate_distance(value:number):boolean { return true; } -static getFullyQualifiedName():string { +static getFullyQualifiedName(): "MyGame.Example.Ability" { return 'MyGame.Example.Ability'; } diff --git a/tests/ts/my-game/example/monster.ts b/tests/ts/my-game/example/monster.ts index 289f609a8..bd64dd121 100644 --- a/tests/ts/my-game/example/monster.ts +++ b/tests/ts/my-game/example/monster.ts @@ -813,7 +813,7 @@ mutate_double_inf_default(value:number):boolean { return true; } -static getFullyQualifiedName():string { +static getFullyQualifiedName(): "MyGame.Example.Monster" { return 'MyGame.Example.Monster'; } diff --git a/tests/ts/my-game/example/referrable.ts b/tests/ts/my-game/example/referrable.ts index 02d8cb1b5..9affeedba 100644 --- a/tests/ts/my-game/example/referrable.ts +++ b/tests/ts/my-game/example/referrable.ts @@ -40,7 +40,7 @@ mutate_id(value:bigint):boolean { return true; } -static getFullyQualifiedName():string { +static getFullyQualifiedName(): "MyGame.Example.Referrable" { return 'MyGame.Example.Referrable'; } diff --git a/tests/ts/my-game/example/stat.ts b/tests/ts/my-game/example/stat.ts index 00b8845f6..72cd032ac 100644 --- a/tests/ts/my-game/example/stat.ts +++ b/tests/ts/my-game/example/stat.ts @@ -63,7 +63,7 @@ mutate_count(value:number):boolean { return true; } -static getFullyQualifiedName():string { +static getFullyQualifiedName(): "MyGame.Example.Stat" { return 'MyGame.Example.Stat'; } diff --git a/tests/ts/my-game/example/struct-of-structs-of-structs.ts b/tests/ts/my-game/example/struct-of-structs-of-structs.ts index 05bc63d52..af3519a01 100644 --- a/tests/ts/my-game/example/struct-of-structs-of-structs.ts +++ b/tests/ts/my-game/example/struct-of-structs-of-structs.ts @@ -20,7 +20,7 @@ a(obj?:StructOfStructs):StructOfStructs|null { return (obj || new StructOfStructs()).__init(this.bb_pos, this.bb!); } -static getFullyQualifiedName():string { +static getFullyQualifiedName(): "MyGame.Example.StructOfStructsOfStructs" { return 'MyGame.Example.StructOfStructsOfStructs'; } diff --git a/tests/ts/my-game/example/struct-of-structs.ts b/tests/ts/my-game/example/struct-of-structs.ts index e1fd746c0..2f4a36748 100644 --- a/tests/ts/my-game/example/struct-of-structs.ts +++ b/tests/ts/my-game/example/struct-of-structs.ts @@ -29,7 +29,7 @@ c(obj?:Ability):Ability|null { return (obj || new Ability()).__init(this.bb_pos + 12, this.bb!); } -static getFullyQualifiedName():string { +static getFullyQualifiedName(): "MyGame.Example.StructOfStructs" { return 'MyGame.Example.StructOfStructs'; } diff --git a/tests/ts/my-game/example/test-simple-table-with-enum.ts b/tests/ts/my-game/example/test-simple-table-with-enum.ts index ef6fa5d83..3e8b4c03f 100644 --- a/tests/ts/my-game/example/test-simple-table-with-enum.ts +++ b/tests/ts/my-game/example/test-simple-table-with-enum.ts @@ -41,7 +41,7 @@ mutate_color(value:Color):boolean { return true; } -static getFullyQualifiedName():string { +static getFullyQualifiedName(): "MyGame.Example.TestSimpleTableWithEnum" { return 'MyGame.Example.TestSimpleTableWithEnum'; } diff --git a/tests/ts/my-game/example/test.ts b/tests/ts/my-game/example/test.ts index db9263cfe..40fff16e6 100644 --- a/tests/ts/my-game/example/test.ts +++ b/tests/ts/my-game/example/test.ts @@ -33,7 +33,7 @@ mutate_b(value:number):boolean { return true; } -static getFullyQualifiedName():string { +static getFullyQualifiedName(): "MyGame.Example.Test" { return 'MyGame.Example.Test'; } diff --git a/tests/ts/my-game/example/type-aliases.ts b/tests/ts/my-game/example/type-aliases.ts index 9f0ed0b26..2897e9738 100644 --- a/tests/ts/my-game/example/type-aliases.ts +++ b/tests/ts/my-game/example/type-aliases.ts @@ -214,7 +214,7 @@ vf64Array():Float64Array|null { return offset ? new Float64Array(this.bb!.bytes().buffer, this.bb!.bytes().byteOffset + this.bb!.__vector(this.bb_pos + offset), this.bb!.__vector_len(this.bb_pos + offset)) : null; } -static getFullyQualifiedName():string { +static getFullyQualifiedName(): "MyGame.Example.TypeAliases" { return 'MyGame.Example.TypeAliases'; } diff --git a/tests/ts/my-game/example/vec3.ts b/tests/ts/my-game/example/vec3.ts index 88c0dbf72..a2092d700 100644 --- a/tests/ts/my-game/example/vec3.ts +++ b/tests/ts/my-game/example/vec3.ts @@ -66,7 +66,7 @@ test3(obj?:Test):Test|null { return (obj || new Test()).__init(this.bb_pos + 26, this.bb!); } -static getFullyQualifiedName():string { +static getFullyQualifiedName(): "MyGame.Example.Vec3" { return 'MyGame.Example.Vec3'; } diff --git a/tests/ts/my-game/example2/monster.ts b/tests/ts/my-game/example2/monster.ts index 39bf68d9e..2016c84e7 100644 --- a/tests/ts/my-game/example2/monster.ts +++ b/tests/ts/my-game/example2/monster.ts @@ -24,7 +24,7 @@ static getSizePrefixedRootAsMonster(bb:flatbuffers.ByteBuffer, obj?:Monster):Mon return (obj || new Monster()).__init(bb.readInt32(bb.position()) + bb.position(), bb); } -static getFullyQualifiedName():string { +static getFullyQualifiedName(): "MyGame.Example2.Monster" { return 'MyGame.Example2.Monster'; } diff --git a/tests/ts/my-game/in-parent-namespace.ts b/tests/ts/my-game/in-parent-namespace.ts index 02f18e1ae..1b67a08db 100644 --- a/tests/ts/my-game/in-parent-namespace.ts +++ b/tests/ts/my-game/in-parent-namespace.ts @@ -24,7 +24,7 @@ static getSizePrefixedRootAsInParentNamespace(bb:flatbuffers.ByteBuffer, obj?:In return (obj || new InParentNamespace()).__init(bb.readInt32(bb.position()) + bb.position(), bb); } -static getFullyQualifiedName():string { +static getFullyQualifiedName(): "MyGame.InParentNamespace" { return 'MyGame.InParentNamespace'; } diff --git a/tests/ts/optional-scalars/scalar-stuff.ts b/tests/ts/optional-scalars/scalar-stuff.ts index e76088bce..7f6fdcaae 100644 --- a/tests/ts/optional-scalars/scalar-stuff.ts +++ b/tests/ts/optional-scalars/scalar-stuff.ts @@ -209,7 +209,7 @@ defaultEnum():OptionalByte { return offset ? this.bb!.readInt8(this.bb_pos + offset) : OptionalByte.One; } -static getFullyQualifiedName():string { +static getFullyQualifiedName(): "optional_scalars.ScalarStuff" { return 'optional_scalars.ScalarStuff'; } diff --git a/tests/ts/union_vector/attacker.ts b/tests/ts/union_vector/attacker.ts index 32675bcd5..aecd4152a 100644 --- a/tests/ts/union_vector/attacker.ts +++ b/tests/ts/union_vector/attacker.ts @@ -40,7 +40,7 @@ mutate_sword_attack_damage(value:number):boolean { return true; } -static getFullyQualifiedName():string { +static getFullyQualifiedName(): "Attacker" { return 'Attacker'; } diff --git a/tests/ts/union_vector/book-reader.ts b/tests/ts/union_vector/book-reader.ts index 2052fdcb2..0fbb4c894 100644 --- a/tests/ts/union_vector/book-reader.ts +++ b/tests/ts/union_vector/book-reader.ts @@ -24,7 +24,7 @@ mutate_books_read(value:number):boolean { return true; } -static getFullyQualifiedName():string { +static getFullyQualifiedName(): "BookReader" { return 'BookReader'; } diff --git a/tests/ts/union_vector/falling-tub.ts b/tests/ts/union_vector/falling-tub.ts index 32fb9fa4a..999a87ea0 100644 --- a/tests/ts/union_vector/falling-tub.ts +++ b/tests/ts/union_vector/falling-tub.ts @@ -24,7 +24,7 @@ mutate_weight(value:number):boolean { return true; } -static getFullyQualifiedName():string { +static getFullyQualifiedName(): "FallingTub" { return 'FallingTub'; } diff --git a/tests/ts/union_vector/hand-fan.ts b/tests/ts/union_vector/hand-fan.ts index 03b809d3d..ca0d2e702 100644 --- a/tests/ts/union_vector/hand-fan.ts +++ b/tests/ts/union_vector/hand-fan.ts @@ -40,7 +40,7 @@ mutate_length(value:number):boolean { return true; } -static getFullyQualifiedName():string { +static getFullyQualifiedName(): "HandFan" { return 'HandFan'; } diff --git a/tests/ts/union_vector/movie.ts b/tests/ts/union_vector/movie.ts index f3457fb43..2c6235e20 100644 --- a/tests/ts/union_vector/movie.ts +++ b/tests/ts/union_vector/movie.ts @@ -67,7 +67,7 @@ charactersLength():number { return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; } -static getFullyQualifiedName():string { +static getFullyQualifiedName(): "Movie" { return 'Movie'; } diff --git a/tests/ts/union_vector/rapunzel.ts b/tests/ts/union_vector/rapunzel.ts index 433106a65..8affb9671 100644 --- a/tests/ts/union_vector/rapunzel.ts +++ b/tests/ts/union_vector/rapunzel.ts @@ -24,7 +24,7 @@ mutate_hair_length(value:number):boolean { return true; } -static getFullyQualifiedName():string { +static getFullyQualifiedName(): "Rapunzel" { return 'Rapunzel'; }