mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-23 17:10:01 +00:00
[TS] Make strict compliant and improve typings (#7549)
* [TS] Make strict compliant and improve typings * clang-format * Code gen harmonize Co-authored-by: Derek Bailey <derekbailey@google.com>
This commit is contained in:
@@ -4,7 +4,7 @@ import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
|
||||
|
||||
export class Attacker {
|
||||
export class Attacker implements flatbuffers.IUnpackableObject<AttackerT> {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):Attacker {
|
||||
@@ -73,7 +73,7 @@ unpackTo(_o: AttackerT): void {
|
||||
}
|
||||
}
|
||||
|
||||
export class AttackerT {
|
||||
export class AttackerT implements flatbuffers.IGeneratedObject {
|
||||
constructor(
|
||||
public swordAttackDamage: number = 0
|
||||
){}
|
||||
|
||||
@@ -4,7 +4,7 @@ import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
|
||||
|
||||
export class BookReader {
|
||||
export class BookReader implements flatbuffers.IUnpackableObject<BookReaderT> {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):BookReader {
|
||||
@@ -49,7 +49,7 @@ unpackTo(_o: BookReaderT): void {
|
||||
}
|
||||
}
|
||||
|
||||
export class BookReaderT {
|
||||
export class BookReaderT implements flatbuffers.IGeneratedObject {
|
||||
constructor(
|
||||
public booksRead: number = 0
|
||||
){}
|
||||
|
||||
@@ -4,7 +4,7 @@ import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
|
||||
|
||||
export class FallingTub {
|
||||
export class FallingTub implements flatbuffers.IUnpackableObject<FallingTubT> {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):FallingTub {
|
||||
@@ -49,7 +49,7 @@ unpackTo(_o: FallingTubT): void {
|
||||
}
|
||||
}
|
||||
|
||||
export class FallingTubT {
|
||||
export class FallingTubT implements flatbuffers.IGeneratedObject {
|
||||
constructor(
|
||||
public weight: number = 0
|
||||
){}
|
||||
|
||||
@@ -4,7 +4,7 @@ import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
|
||||
|
||||
export class HandFan {
|
||||
export class HandFan implements flatbuffers.IUnpackableObject<HandFanT> {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):HandFan {
|
||||
@@ -73,7 +73,7 @@ unpackTo(_o: HandFanT): void {
|
||||
}
|
||||
}
|
||||
|
||||
export class HandFanT {
|
||||
export class HandFanT implements flatbuffers.IGeneratedObject {
|
||||
constructor(
|
||||
public length: number = 0
|
||||
){}
|
||||
|
||||
@@ -107,7 +107,7 @@ export class Movie {
|
||||
}
|
||||
unpack() {
|
||||
return new MovieT(this.mainCharacterType(), (() => {
|
||||
let temp = unionToCharacter(this.mainCharacterType(), this.mainCharacter.bind(this));
|
||||
const temp = unionToCharacter(this.mainCharacterType(), this.mainCharacter.bind(this));
|
||||
if (temp === null) {
|
||||
return null;
|
||||
}
|
||||
@@ -116,13 +116,13 @@ export class Movie {
|
||||
}
|
||||
return temp.unpack();
|
||||
})(), this.bb.createScalarList(this.charactersType.bind(this), this.charactersTypeLength()), (() => {
|
||||
let ret = [];
|
||||
const ret = [];
|
||||
for (let targetEnumIndex = 0; targetEnumIndex < this.charactersTypeLength(); ++targetEnumIndex) {
|
||||
let targetEnum = this.charactersType(targetEnumIndex);
|
||||
const targetEnum = this.charactersType(targetEnumIndex);
|
||||
if (targetEnum === null || Character[targetEnum] === 'NONE') {
|
||||
continue;
|
||||
}
|
||||
let temp = unionListToCharacter(targetEnum, this.characters.bind(this), targetEnumIndex);
|
||||
const temp = unionListToCharacter(targetEnum, this.characters.bind(this), targetEnumIndex);
|
||||
if (temp === null) {
|
||||
continue;
|
||||
}
|
||||
@@ -138,7 +138,7 @@ export class Movie {
|
||||
unpackTo(_o) {
|
||||
_o.mainCharacterType = this.mainCharacterType();
|
||||
_o.mainCharacter = (() => {
|
||||
let temp = unionToCharacter(this.mainCharacterType(), this.mainCharacter.bind(this));
|
||||
const temp = unionToCharacter(this.mainCharacterType(), this.mainCharacter.bind(this));
|
||||
if (temp === null) {
|
||||
return null;
|
||||
}
|
||||
@@ -149,13 +149,13 @@ export class Movie {
|
||||
})();
|
||||
_o.charactersType = this.bb.createScalarList(this.charactersType.bind(this), this.charactersTypeLength());
|
||||
_o.characters = (() => {
|
||||
let ret = [];
|
||||
const ret = [];
|
||||
for (let targetEnumIndex = 0; targetEnumIndex < this.charactersTypeLength(); ++targetEnumIndex) {
|
||||
let targetEnum = this.charactersType(targetEnumIndex);
|
||||
const targetEnum = this.charactersType(targetEnumIndex);
|
||||
if (targetEnum === null || Character[targetEnum] === 'NONE') {
|
||||
continue;
|
||||
}
|
||||
let temp = unionListToCharacter(targetEnum, this.characters.bind(this), targetEnumIndex);
|
||||
const temp = unionListToCharacter(targetEnum, this.characters.bind(this), targetEnumIndex);
|
||||
if (temp === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import { Character, unionToCharacter, unionListToCharacter } from './character.j
|
||||
import { Rapunzel, RapunzelT } from './rapunzel.js';
|
||||
|
||||
|
||||
export class Movie {
|
||||
export class Movie implements flatbuffers.IUnpackableObject<MovieT> {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):Movie {
|
||||
@@ -139,19 +139,19 @@ unpack(): MovieT {
|
||||
return new MovieT(
|
||||
this.mainCharacterType(),
|
||||
(() => {
|
||||
let temp = unionToCharacter(this.mainCharacterType(), this.mainCharacter.bind(this));
|
||||
const temp = unionToCharacter(this.mainCharacterType(), this.mainCharacter.bind(this));
|
||||
if(temp === null) { return null; }
|
||||
if(typeof temp === 'string') { return temp; }
|
||||
return temp.unpack()
|
||||
})(),
|
||||
this.bb!.createScalarList(this.charactersType.bind(this), this.charactersTypeLength()),
|
||||
this.bb!.createScalarList<Character>(this.charactersType.bind(this), this.charactersTypeLength()),
|
||||
(() => {
|
||||
let ret = [];
|
||||
const ret = [];
|
||||
for(let targetEnumIndex = 0; targetEnumIndex < this.charactersTypeLength(); ++targetEnumIndex) {
|
||||
let targetEnum = this.charactersType(targetEnumIndex);
|
||||
const targetEnum = this.charactersType(targetEnumIndex);
|
||||
if(targetEnum === null || Character[targetEnum!] === 'NONE') { continue; }
|
||||
|
||||
let temp = unionListToCharacter(targetEnum, this.characters.bind(this), targetEnumIndex);
|
||||
const temp = unionListToCharacter(targetEnum, this.characters.bind(this), targetEnumIndex);
|
||||
if(temp === null) { continue; }
|
||||
if(typeof temp === 'string') { ret.push(temp); continue; }
|
||||
ret.push(temp.unpack());
|
||||
@@ -165,19 +165,19 @@ unpack(): MovieT {
|
||||
unpackTo(_o: MovieT): void {
|
||||
_o.mainCharacterType = this.mainCharacterType();
|
||||
_o.mainCharacter = (() => {
|
||||
let temp = unionToCharacter(this.mainCharacterType(), this.mainCharacter.bind(this));
|
||||
const temp = unionToCharacter(this.mainCharacterType(), this.mainCharacter.bind(this));
|
||||
if(temp === null) { return null; }
|
||||
if(typeof temp === 'string') { return temp; }
|
||||
return temp.unpack()
|
||||
})();
|
||||
_o.charactersType = this.bb!.createScalarList(this.charactersType.bind(this), this.charactersTypeLength());
|
||||
_o.charactersType = this.bb!.createScalarList<Character>(this.charactersType.bind(this), this.charactersTypeLength());
|
||||
_o.characters = (() => {
|
||||
let ret = [];
|
||||
const ret = [];
|
||||
for(let targetEnumIndex = 0; targetEnumIndex < this.charactersTypeLength(); ++targetEnumIndex) {
|
||||
let targetEnum = this.charactersType(targetEnumIndex);
|
||||
const targetEnum = this.charactersType(targetEnumIndex);
|
||||
if(targetEnum === null || Character[targetEnum!] === 'NONE') { continue; }
|
||||
|
||||
let temp = unionListToCharacter(targetEnum, this.characters.bind(this), targetEnumIndex);
|
||||
const temp = unionListToCharacter(targetEnum, this.characters.bind(this), targetEnumIndex);
|
||||
if(temp === null) { continue; }
|
||||
if(typeof temp === 'string') { ret.push(temp); continue; }
|
||||
ret.push(temp.unpack());
|
||||
@@ -187,7 +187,7 @@ unpackTo(_o: MovieT): void {
|
||||
}
|
||||
}
|
||||
|
||||
export class MovieT {
|
||||
export class MovieT implements flatbuffers.IGeneratedObject {
|
||||
constructor(
|
||||
public mainCharacterType: Character = Character.NONE,
|
||||
public mainCharacter: AttackerT|BookReaderT|RapunzelT|string|null = null,
|
||||
|
||||
@@ -4,7 +4,7 @@ import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
|
||||
|
||||
export class Rapunzel {
|
||||
export class Rapunzel implements flatbuffers.IUnpackableObject<RapunzelT> {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):Rapunzel {
|
||||
@@ -49,7 +49,7 @@ unpackTo(_o: RapunzelT): void {
|
||||
}
|
||||
}
|
||||
|
||||
export class RapunzelT {
|
||||
export class RapunzelT implements flatbuffers.IGeneratedObject {
|
||||
constructor(
|
||||
public hairLength: number = 0
|
||||
){}
|
||||
|
||||
Reference in New Issue
Block a user