Skip to content

Commit

Permalink
chore(win32-def): fix types of StructType()
Browse files Browse the repository at this point in the history
  • Loading branch information
waitingsong committed Jul 1, 2022
1 parent d1be460 commit 2fd0022
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/win32-def/src/lib/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ export function UnionFactor<T>(input: StructDefType): T {
}

const Struct = StructDi(ref)
export function StructType<T>(input: StructDefType): T {
export function StructType(input: StructDefType) {
// @ts-expect-error
return Struct(input) as unknown as T
return Struct(input)
}
export function StructFactory<T>(input: StructDefType): T {
// @ts-expect-error
Expand Down
50 changes: 50 additions & 0 deletions packages/win32-def/test/20.helper.test.ts
Original file line number Diff line number Diff line change
@@ -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<POINT>(DS.POINT)
assert(point)
point.x = 101
point.y = rnd

assert(point.x === 101)
assert(point.y === rnd)
})
})

})

0 comments on commit 2fd0022

Please sign in to comment.