flatbuffers icon indicating copy to clipboard operation
flatbuffers copied to clipboard

[TS] Weakened typing for unions in version 2

Open stephanemagnenat opened this issue 2 years ago • 10 comments

It seems that with flatc 2.0.0, the generated calls for unions have weakened type. Taking the monster tutorial as example, a struct having a member equipped of type Equipment will now generate the following method:

equipped<T extends flatbuffers.Table>(obj:any):any|null { ... }

while before 2.0, the following method would be generated:

equipped<T extends flatbuffers.Table>(obj:T):T|null { ... }

This is a problem, because before the type system would ensure that if the right object is passed in, the right object gets out. Now we do not even have this assurance, forcing to decorate this call with as InputType like in:

const equipment = monster.equipped(new Equipment()) as Equipment | null;

Is there a reason for this weakening? The template parameter is still in the generated code, but it is not used any more...

stephanemagnenat avatar Jul 19 '21 15:07 stephanemagnenat

@bjornharrtell

aardappel avatar Jul 19 '21 18:07 aardappel

Agreed likely unintended regression.

bjornharrtell avatar Jul 19 '21 21:07 bjornharrtell

This issue is stale because it has been open 6 months with no activity. Please comment or this will be closed in 14 days.

github-actions[bot] avatar Jan 18 '22 20:01 github-actions[bot]

Commenting to avoid stale issue deletion. I think we want this addressed.

sketch34 avatar Jan 19 '22 04:01 sketch34

This issue is stale because it has been open 6 months with no activity. Please comment or label not-stale, or this will be closed in 14 days.

github-actions[bot] avatar Mar 04 '23 01:03 github-actions[bot]

Commenting to avoid stale issue deletion.

stephanemagnenat avatar Mar 06 '23 08:03 stephanemagnenat

This issue is stale because it has been open 6 months with no activity. Please comment or label not-stale, or this will be closed in 14 days.

github-actions[bot] avatar Sep 05 '23 20:09 github-actions[bot]

Commenting to avoid stale issue deletion.

stephanemagnenat avatar Sep 06 '23 11:09 stephanemagnenat

This issue is stale because it has been open 6 months with no activity. Please comment or label not-stale, or this will be closed in 14 days.

github-actions[bot] avatar Mar 06 '24 20:03 github-actions[bot]

Commenting to avoid stale issue deletion.

stephanemagnenat avatar Mar 06 '24 21:03 stephanemagnenat