Skip to content

Commit

Permalink
add type assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
canalun committed Mar 4, 2024
1 parent e3791d4 commit 3328753
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
14 changes: 8 additions & 6 deletions src/game/animation/updateBlocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,15 @@ function removeBlock(block: Block) {
Array.from(block.element.children).forEach((childEl) => {
originalVisibilities.push(getComputedStyleWithCache(childEl).visibility)
})
Object.assign(block.element.style, {
visibility: "hidden"
})
Array.from(block.element.children).forEach((childEl, i) => {
Object.assign(childEl.style, {
visibility: originalVisibilities[i]
;(block.element as HTMLElement).style && // TODO: remove type assertion
Object.assign((block.element as HTMLElement).style, {
visibility: "hidden"
})
Array.from(block.element.children).forEach((childEl, i) => {
;(childEl as HTMLElement).style && // TODO: remove type assertion
Object.assign((childEl as HTMLElement).style, {
visibility: originalVisibilities[i]
})
})
}

Expand Down
14 changes: 8 additions & 6 deletions src/game/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ export function visualizeBlocks(blocks: Block[]) {
for (let i = 0; i < blocks.length; i++) {
const blockElement = blocks[i].element
if (blocks[i].remain) {
Object.assign(blockElement.style, {
border: "0.1px solid red"
})
;(blockElement as HTMLElement).style && // TODO: remove type assertion
Object.assign((blockElement as HTMLElement).style, {
border: "0.1px solid red"
})
} else {
Object.assign(blockElement.style, {
border: "none"
})
;(blockElement as HTMLElement).style && // TODO: remove type assertion
Object.assign((blockElement as HTMLElement).style, {
border: "none"
})
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/game/object/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getBlockElements } from "./getBlockElements"
// and then it's "removed" when remove animation is done.
export type Block = {
uuid: string
element: Element
element: Element // this includes not only HTMLElement but also others like SVGElement.
rect: {
top: number
bottom: number
Expand Down

0 comments on commit 3328753

Please sign in to comment.