Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Fix possibly-null type errors #4

Merged
merged 2 commits into from
Mar 10, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Data/SendPropDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class SendPropDefinition {
highValue: number;
bitCount: number;
table: SendTable|null;
numElements: number|null;
numElements: number;
arrayProperty: SendPropDefinition|null;
ownerTableName: string;

Expand All @@ -21,7 +21,7 @@ export class SendPropDefinition {
this.highValue = 0;
this.bitCount = 0;
this.table = null;
this.numElements = null;
this.numElements = 0;
this.arrayProperty = null;
this.ownerTableName = ownerTableName;
}
Expand Down
2 changes: 1 addition & 1 deletion src/PacketHandler/PacketEntities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function handleEntity(entity: PacketEntity, match: Match) {
}
}
if (prop.definition.ownerTableName === 'm_iAmmo') {
if (prop.value > 0) {
if (prop.value && prop.value > 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The >0 shouldn't be needed since 0 is will evaluate to false

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made it more specific. The type issue is that prop.value can be null there, so checking prop.value > 0 is throwing error TS2531: Object is possibly 'null'

player.ammo[parseInt(prop.definition.name, 10)] = <number>prop.value;
}
}
Expand Down