From 2fd00222ed27fcbdc54d0e7bbf36a406652f9548 Mon Sep 17 00:00:00 2001 From: waiting <1661926154@qq.com> Date: Fri, 1 Jul 2022 14:02:14 +0800 Subject: [PATCH] chore(win32-def): fix types of StructType() --- packages/win32-def/src/lib/helper.ts | 4 +- packages/win32-def/test/20.helper.test.ts | 50 +++++++++++++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 packages/win32-def/test/20.helper.test.ts diff --git a/packages/win32-def/src/lib/helper.ts b/packages/win32-def/src/lib/helper.ts index 7f677a00..df0c2752 100644 --- a/packages/win32-def/src/lib/helper.ts +++ b/packages/win32-def/src/lib/helper.ts @@ -18,9 +18,9 @@ export function UnionFactor(input: StructDefType): T { } const Struct = StructDi(ref) -export function StructType(input: StructDefType): T { +export function StructType(input: StructDefType) { // @ts-expect-error - return Struct(input) as unknown as T + return Struct(input) } export function StructFactory(input: StructDefType): T { // @ts-expect-error diff --git a/packages/win32-def/test/20.helper.test.ts b/packages/win32-def/test/20.helper.test.ts new file mode 100644 index 00000000..427914a6 --- /dev/null +++ b/packages/win32-def/test/20.helper.test.ts @@ -0,0 +1,50 @@ +import assert from 'node:assert/strict' + +import { fileShortPath } from '@waiting/shared-core' + +import { + POINT, + StructFactory, + StructType, +} from '../src/index.js' +import * as DS from '../src/index.struct.js' + + +describe(fileShortPath(import.meta.url), () => { + + describe('StructType() should work', () => { + it('normal', () => { + const rnd = Math.round(Math.random() * 1000000) + + const poinitInit = StructType(DS.POINT) + assert(poinitInit) + // @ts-expect-error + assert(typeof poinitInit.x === 'undefined') + // @ts-expect-error + assert(typeof poinitInit.y === 'undefined') + + const point = new poinitInit() + assert(point) + point.x = 101 + point.y = rnd + + assert(point.x === 101) + assert(point.y === rnd) + }) + }) + + describe('StructFactory() should work', () => { + it('normal', () => { + const rnd = Math.round(Math.random() * 1000000) + const point = StructFactory(DS.POINT) + assert(point) + point.x = 101 + point.y = rnd + + assert(point.x === 101) + assert(point.y === rnd) + }) + }) + +}) +