Skip to content

Commit

Permalink
Merge pull request #30 from kubk/ts-assertion
Browse files Browse the repository at this point in the history
Use TS assertion signature to avoid type casting
  • Loading branch information
Francis Stokes committed Jan 9, 2022
2 parents 1122af1 + 6bbf1df commit 2ca1851
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const assert = (condition: boolean, message: string) => {
function assert(condition: boolean, message: string): asserts condition {
if (!condition) {
throw new Error(message);
}
Expand Down Expand Up @@ -76,7 +76,7 @@ export class StructType implements IField {
}

assert(nextPart instanceof StructType, `Item in path "${head}" is not a Struct`);
return (nextPart as StructType).getDeep<T>(tail.join('.'));
return nextPart.getDeep<T>(tail.join('.'));
}

getDeepOffset(path: string, startOffset = 0): number {
Expand All @@ -91,7 +91,7 @@ export class StructType implements IField {
}

assert(nextPart instanceof StructType, `Item in path "${head}" is not a Struct`);
return (nextPart as StructType).getDeepOffset(tail.join('.'), nextOffset);
return nextPart.getDeepOffset(tail.join('.'), nextOffset);
}

getOffset(name: string) {
Expand Down

0 comments on commit 2ca1851

Please sign in to comment.