From 6bbf1dfb0f019f5f68b13952614cb78fe73d314e Mon Sep 17 00:00:00 2001 From: Gorbachev Egor <7gorbachevm@gmail.com> Date: Sun, 9 Jan 2022 11:53:50 +0300 Subject: [PATCH] Use TS assertion signature to avoid type casting --- src/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index e2487eb..7918214 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -const assert = (condition: boolean, message: string) => { +function assert(condition: boolean, message: string): asserts condition { if (!condition) { throw new Error(message); } @@ -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(tail.join('.')); + return nextPart.getDeep(tail.join('.')); } getDeepOffset(path: string, startOffset = 0): number { @@ -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) {