DragonBones / DragonBonesJS

DragonBones TypeScript / JavaScript Runtime
MIT License
746 stars 320 forks source link

Fix type error, assigning Int16 to Uint16 colors #115

Closed alcalyn closed 5 years ago

alcalyn commented 5 years ago

I got a type error from Typescript:

ERROR in /app/node_modules/dragonbones-runtime/DragonBones/src/dragonBones/parser/BinaryDataParser.ts
[tsl] ERROR in /app/node_modules/dragonbones-runtime/DragonBones/src/dragonBones/parser/BinaryDataParser.ts(384,13)
      TS2322: Type 'Int16Array' is not assignable to type 'Uint16Array'.
  Types of property '[Symbol.toStringTag]' are incompatible.
    Type '"Int16Array"' is not assignable to type '"Uint16Array"'.

ERROR in /app/node_modules/dragonbones-runtime/DragonBones/src/dragonBones/parser/ObjectDataParser.ts
[tsl] ERROR in /app/node_modules/dragonbones-runtime/DragonBones/src/dragonBones/parser/ObjectDataParser.ts(2290,13)
      TS2322: Type 'Int16Array' is not assignable to type 'Uint16Array'.

When checking the source code, I can see:

public colorArray: Uint16Array;

The unsigned type seems fine for a color representation, but later in the code, it is trying to assign a signed integer to this color attribute.

This PR fixes these errors by using unsigned integers when working with colors.

Note: A quick hack was to change colorArray to a signed type, this only diff is clearing errors, but not sure if it is a good solution.