Resolving TypeScript syntax errors
September 01, 2020
타입스크립트 사용시 문법에러 해결하기
userRef Object is possibly ‘null’.
const fixRef = useRef(null)
const fixRef: any = useRef(null)
console.log(fixRef.current.clientHeight)
window.property Error
var particles = (window.particles = []);
declare global {
interface Window {
particles: any;
}
}
[] as any
Argument of type ‘any’ is not assignable to parameter of type ‘never
router
import { BrowserRouter } from "react-router-dom"
ould not find a declaration file for module ‘react-router-dom’. ‘/Users/songs 1/Desktop/github/motionbox/node_modules/react-router-dom/index.js’ implicitly has an ‘any’ type. Try
npm install @types/react-router-dom
if it exists or add a new declaration (.d.ts) file containingdeclare module 'react-router-dom';
TS7016
npm install @types/react-router-dom
Module not found: Can’t resolve ‘react-router-dom’ in
// 모듈 재설치
npm install
const sets: unknown[] ‘unknown[]’ 형식의 인수는 ‘SetStateAction’ 형식의 매개 변수에 할당될 수 없습니다. ‘unknown[]’ 형식은 ‘never[]’ 형식에 할당할 수 없습니다. ‘unknown’ 형식은 ‘never’ 형식에 할당할 수 없습니다.
useState([]);
useState([] as any);
tsconfig.js
"downlevelIteration": true
@ts-ignore
Error No overload matches this call. Overload 1 of 2, ’(config: InterpolationConfig): { interpolate: InterpolationChain; getValue: () => string | undefined; } & string’, gave the following error. ’(x: number, y: number) => string’ 형식의 인수는 ‘InterpolationConfig’ 형식의 매개 변수에 할당될 수 없습니다. Type ’(x: number, y: number) => string’ is missing the following properties from type ‘InterpolationConfig’: range, output Overload 2 of 2, ’(interpolator: (params: number[]) => string): OpaqueInterpolation’, gave the following error. ’(x: number, y: number) => string’ 형식의 인수는 ’(params: number[]) => string’ 형식의 매개 변수에 할당될 수 없습니다.ts(2769)
// @ts-ignore 추가
(x, y) => `translate3D(${x}px, ${y}px, 0)`
// @ts-ignore
(x, y) => `translate3D(${x}px, ${y}px, 0)`
querySelectorAll style Error <HTMLElement>
Property ‘style’ does not exist on type ‘Element’
const motionP = document.querySelectorAll(".motionElem")
const motionP = document.querySelectorAll<HTMLElement>(".motionElem")