Javascript/Typescript 6

Redux useSelector 사용시, 귀찮은 RootState(AppState)을 없애기

현재 팀에서는 typescript를 사용하지 않아 매우 불편하다. typescript 도입하고 싶다고 하였지만, 여러번 반려당했다. 이유를 들어보면 어느정도 이해는 되긴한다. 그래서 나는 처음으로 typescript 없이 오직 javacsript 만으로 코딩을 하기 시작하였다. 여러 불편함을 너무 발견하였고, tight하게 타입을 정의하기보다는 loose하게 작업하자고 생각하였다. 그래서 혼자서 작업을 하고 있다. 현재 내가하는 목표는 prmitive type을 넣기보다는 property(object key etc.)를 추론할 수 있도록 타입을 넣고 있다. redux를 사용하게 되면 아래처럼 RootState를 import해서 많이 사용할 것이다. 이 코드의 문제점은 useSelector를 사용하는 곳은..

[Typescript] storybook에서 절대 경로 설정하기

1. 먼저 tsconfig에 path 셋팅을 한다. // tsconfig.json { "compilerOptions": { "baseUrl": "./src", "paths": { "@components/*": ["components/*"], } } } 2. storybook 셋팅에서 TsconfigPathsPlugin를 추가해준다. // .storybook/main.js const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin') module.exports = { webpackFinal: async (config) => { config.resolve.plugins.push(new TsconfigPathsPlugin({})); r..

타입스크립트에서 특정 prop을 제외시키기 ( Omit )

interface Test { a: string; b: number; c: boolean; } type OmitA = Omit; // Equivalent to: {b: number, c: boolean} type OmitAB = Omit; // Equivalent to: {c: boolean} const a: OmitA = { a: 'aa', b: 1, c: true } const b: OmitAB = { a: 'aa', b: 1, c: true } Omit 은 optional으로 된 prop이 사라지는 버그가 있었는데 3.5에서 패치가 되었다. interface Test { a?: string; b?: number; c?: boolean; } type OmitA = Omit; // Equivalent ..