Skip to content

Commit

Permalink
chore: explicitly narrow the ctx type
Browse files Browse the repository at this point in the history
  • Loading branch information
GZTimeWalker committed Jan 19, 2025
1 parent 0ae3ff7 commit 22951ad
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/GZCTF/ClientApp/src/hooks/useForeground.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { FastAverageColor } from 'fast-average-color'
import { useState, useEffect } from 'react'

type RenderingCtx = CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D

export const useForeground = (image?: string | null) => {
const [color, setColor] = useState<string>('var(--mantine-color-text)')

Expand All @@ -23,7 +25,7 @@ export const useForeground = (image?: string | null) => {
? new OffscreenCanvas(imgWidth, imgHeight)
: document.createElement('canvas')

const ctx = canvas.getContext('2d')
const ctx = canvas.getContext('2d') as RenderingCtx | null
if (!ctx) return

ctx.drawImage(img, 0, img.height - imgHeight, imgWidth, imgHeight, 0, 0, imgWidth, imgHeight)
Expand Down
6 changes: 3 additions & 3 deletions src/GZCTF/ClientApp/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
"jsx": "preserve",
"lib": ["dom", "dom.iterable", "esnext"],
"module": "esnext",
"moduleResolution": "Node",
"moduleResolution": "node",
"noEmit": true,
"paths": {
"@Api": ["src/Api.ts"],
"@App": ["src/App"],
"@Components/*": ["src/components/*"],
"@Hooks/*": ["src/hooks/*"],
"@Pages/*": ["src/pages/*"],
"@Resources/*": ["src/resources/*"],
"@Styles/*": ["src/styles/components/*", "src/styles/shared/*", "src/styles/pages/*"],
"@Utils/*": ["src/utils/*"],
"@Hooks/*": ["src/hooks/*"],
"@Utils/*": ["src/utils/*"]
},
"resolveJsonModule": true,
"skipLibCheck": true,
Expand Down

0 comments on commit 22951ad

Please sign in to comment.