본문 바로가기

TypeScript 끄적끄적

(3)
'css' 속성이 없습니다.ts(2322) @types/react/index.d.ts의 HTMLAttributes interface에 css 속성이 없는데, 추가하려고 하니 타입 에러가 발생 (해당 코드: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react/index.d.ts#L1843-L1909) 해결 방법 1. tsconfig.json > compileOptions 에 types 추가 // tsconfig.json { "compilerOptions": { "types": ["@emotion/react/types/css-prop"] } } 2. styles.d.ts 추가 styled.d.ts 파일을 추가하고, 아래 코드를 추가 /// emotion 공식 홈페이지 설명
tsx로 컴포넌트를 만들고 png이미지를 import할때 오류 해결 방법 webpack에서 이미지도 번들링 해주려고, 아래와 같이 설정을 해주니 typescript 쪽에서 해당 에러가 발생했다. // webpack.config.js ... { test: /\.(png|jpe?g)$/, use: { loader: 'file-loader', options: { name: '[path][name].[ext]', }, }, }, ... TS2307: Cannot find module './이름.png' or its corresponding type declarations. 원인은 타입이 정의되어 있지 않아서 이다. Typescript에서 .d.ts 파일을 추가해줘서 타입을 추가할 수 있다. (단, index.d.ts 파일은 index.ts 파일이 생성했다고 Typescript가 추측..
'{ children: never[]; }' 유형에 'IntrinsicAttributes' 유형과 공통적인 속성이 없습니다.ts(2559) TypeScript 에러 발생 Styled-Component를 활용해서 하든 emotion을 사용하든.. 알맞게 css를 적용하고 사용하려고 하는데... /** @jsxImportSource @emotion/react */ import React from 'react' import {css} from '@emotion/react' const LoadingBlock = (props: any) => { const whiteStyle = css` position: absolute; left: 0; top: 0; bottom: 0; right: 0; background: #A4A4A4; display: flex; flex-direction: column; justify-content: center; align-..

728x90