본문 바로가기

Errors18

[Typescript] TS2550: Property 'padStart' does not exist on type 'string'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2017' or later. 충격!!! 원인 padstart가 es2017에 나온거라니..ㅠㅠ 오.. 비교적 최근에 생긴것이다!! es6를 사용하고 있어서 오류가 났다. https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/String/padStart typescript polyfill const padStart = (targetLength: number, padString: string, str: string): string => { return str.length >= targetLength ? str : new Array(targetLength - str.length + 1).join(padString) + str; }; 2021. 8. 22.
[Typescript] TS2307: Cannot find module '.png' or its corresponding type declarations. webpack에서 이미지도 번들링 해주려고, 아래와 같이 설정을 해주니 typescript 쪽에서 해당 에러가 발생했다. // webpack.config.js ... { test: /\.(png|jpe?g)$/, use: { loader: 'file-loader', options: { name: '[path][name].[ext]', }, }, }, ... TS2307: Cannot find module './webpack.png' or its corresponding type declarations. 원인은 타입이 정의되어 있지 않아서 이다. Typescript에서 .d.ts 파일을 추가해줘서 타입을 추가할 수 있다. (단, index.d.ts 파일은 index.ts 파일이 생성했다고 Typescrip.. 2021. 8. 22.
[Typescript] Unknown compiler option 'exactOptionalPropertyTypes'. ts typescript가 로컬 내에 최신 버전으로 업그레이드가 안되어있을 때 발생할 수 있다. -g 옵션을 통해 컴퓨터 내의 typescript을 최신버전으로 업그레이드 해주자. npm install -g typescript@latest 해결!! 2021. 8. 19.
[Typescript] Property 'getBoundingClientRect' does not exist on type 'EventTarget'.ts(2339) canvas의 viewport에 대한 상대적 위치를 알기위해 getBoundingClientRect를 구하면서 발생했다. 원래 코드는 아래와 같다. const paddleThrottleHandler = (event: React.MouseEvent) => { if (event.clientY < event.target.getBoundingClientRect().top + player1.paddleHeight / 2) { updatePlayingInfoHandler({ index: 1, uuid: '1', player1Y: inputName === 'player1' ? 0 : player1Y, player2Y: inputName === 'player2' ? 0 : player2Y, }); } ... 발생 이유.. 2021. 8. 16.
[React] 'React' refers to a UMD global, but the current file is a module. Consider adding an import instead. 문제 발생 다음과 같은 코드에서 tag에서 lint error가 났다. 이유를 알아보자. export const AlarmChatPeople = ({ username, }: { username: string; }) => { return {username}; }; JSX 구문이 변환되는 방식은 컴파일러 옵션 jsxFactory에 따라 다르지만, 기본 값은 React.createComponent이다. tag를 React.createComponent('p') 와같이 변환해 준다. 따라서 명시적인 import React from 'react'; 가 없을 경우 해당 오류가 반환된다. 해결 방법 import React from 'react';을 추가하자. import React from 'react'; export.. 2021. 7. 26.
[React] Error: Invalid hook call. 오류 발생 https://github.com/hochan222/holee-contextmenu hochan222/holee-contextmenu react typescript context menu. Contribute to hochan222/holee-contextmenu development by creating an account on GitHub. github.com npm에 배포하려고 contextmenu 라이브러리를 만드는 와중에 CRA를 사용해서 demo를 만들다가 발생했다. Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one o.. 2021. 7. 17.