제로초님 안녕하세요. 알려주신 방식대로 실행해도 Missing required argument: dataSource 에러가 발생합니다. 직접 마이그레이션 파일을 작성한 뒤 npm run db:migrate를 실행시켜도 마찬가지이고요. datasource가 db connectio 관리하는 객체를 이야기하고, typeorm 문서에 나오는 DataSource 객체 생성 부분은 Nest에서 관리하는 것 같습니다. TypeOrmModule.footRootAsync 함수의 옵션 중에 dataSourceFactory라는 게 있어서 dataSourceFactory: async () => { return new DataSource({ type: 'mysql', host: 'localhost', port: 3306, username: process.env.DB_USERNAME, password: process.env.DB_PASSWORD, database: process.env.DB_DATABASE, entities: [ ChannelChats, ChannelMembers, Channels, DMs, Mentions, Users, WorkspaceMembers, Workspaces, ], migrations: [__dirname + '/src/migrations/*.ts'], charset: 'utf8mb4', synchronize: false, logging: true, }); }, 위처럼 시도해봤는데 효과는 없네요.
와 엄청 빠른 답변 감사합니다. 저 그럼 혹시 package.json에는 변경사항을 어떤 식으로 반영해야할까요? { ... "db:create-migration": "npm run typeorm migration:create -- -n", "db:generate-migration": "npm run typeorm migration:generate -- -n" } 강의에서는 위처럼 설정되어 있는데, -n이 없어졌다고 해서 없애고 돌려보니 dataSource가 필요하다고 해서 entities 폴더를 지정해서 npm run db:generate-migration src/migrations/categoryToType -d src/entities 이렇게 해봤는데 결과가 안 나오네요. 검색해보니까 dataSource라는 게 https://typeorm.biunav.com/en/data-source.html#what-is-datasource 여기 나온 것처럼 DB connection을 담당하는 부분인 것 같은데, 여기서는 어떤 식으로 지정을 해줘야할까요.
질문 올리고 구글링하다가 찾았습니다. https://stackoverflow.com/questions/72682474/typeorm-migrationgenerate-failure-not-enough-non-option-arguments-got-0-need 혹시 도움이 되시는 분들이 있을까 싶어서 질문글은 그냥 남겨두겠습니다. typeorm이 업데이트되면서 변화가 좀 있었네요.
저도 이부분이 잠깐 헷갈렸는데, 머신러닝 프로그램을 일종의 수학적인 함수라고 생각하니 헷갈리지 않게 되었습니다. 어떤 x값을 주었을 때 이에 따른 이에 대응하는 하나의 y값을 반환하는 것을 함수라고 하잖아요. 머신러닝에서 이 x값에 해당하는 것이 feature들이고, y값에 해당하는 것이 target인 셈인데, training data set과 test data set을 나눌 때에도 이 본질적인 의미 아래에서 각각을 training / test로 나누는 것이니 feature인 X를 train, test로 나눈 것이 오고, target인 y를 train, test로 나눈 것이 오게 되는 것으로 이해했습니다. 써놓고 나니 너무 당연한 소리 같기는 한데 누군가에게는 도움이 되길 바랍니다.
제로초님 안녕하세요. 빠른 답변 감사합니다. function useReducer R extends ReducerWithoutAction any > , I >( reducer: R , initializerArg: I , initializer: (arg: I ) => ReducerStateWithoutAction R > ): [ReducerStateWithoutAction R > , DispatchWithoutAction] ; /** * An alternative to `useState`. * * `useReducer` is usually preferable to `useState` when you have complex state logic that involves * multiple sub-values. It also lets you optimize performance for components that trigger deep * updates because you can pass `dispatch` down instead of callbacks. * * @version 16.8.0 * @see https://reactjs.org/docs/hooks-reference.html#usereducer */ // overload where dispatch could accept 0 arguments. function useReducer R extends ReducerWithoutAction any >>( reducer: R , initializerArg: ReducerStateWithoutAction R > , initializer?: undefined ): [ReducerStateWithoutAction R > , DispatchWithoutAction] ; /** * An alternative to `useState`. * * `useReducer` is usually preferable to `useState` when you have complex state logic that involves * multiple sub-values. It also lets you optimize performance for components that trigger deep * updates because you can pass `dispatch` down instead of callbacks. * * @version 16.8.0 * @see https://reactjs.org/docs/hooks-reference.html#usereducer */ // overload where "I" may be a subset of ReducerState ; used to provide autocompletion. // If "I" matches ReducerState exactly then the last overload will allow initializer to be omitted. // the last overload effectively behaves as if the identity function (x => x) is the initializer. function useReducer R extends Reducer any, any > , I >( reducer: R , initializerArg: I & ReducerState R > , initializer: (arg: I & ReducerState R >) => ReducerState R > ): [ReducerState R > , Dispatch R >>] ; /** * An alternative to `useState`. * * `useReducer` is usually preferable to `useState` when you have complex state logic that involves * multiple sub-values. It also lets you optimize performance for components that trigger deep * updates because you can pass `dispatch` down instead of callbacks. * * @version 16.8.0 * @see https://reactjs.org/docs/hooks-reference.html#usereducer */ // overload for free "I"; all goes as long as initializer converts it into "ReducerState ". function useReducer R extends Reducer any, any > , I >( reducer: R , initializerArg: I , initializer: (arg: I ) => ReducerState R > ): [ReducerState R > , Dispatch R >>] ; /** * An alternative to `useState`. * * `useReducer` is usually preferable to `useState` when you have complex state logic that involves * multiple sub-values. It also lets you optimize performance for components that trigger deep * updates because you can pass `dispatch` down instead of callbacks. * * @version 16.8.0 * @see https://reactjs.org/docs/hooks-reference.html#usereducer */ // I'm not sure if I keep this 2-ary or if I make it (2,3)-ary; it's currently (2,3)-ary. // The Flow types do have an overload for 3-ary invocation with undefined initializer. // NOTE: without the ReducerState indirection, TypeScript would reduce S to be the most common // supertype between the reducer's return type and the initialState (or the initializer's return type), // which would prevent autocompletion from ever working. // TODO: double-check if this weird overload logic is necessary. It is possible it's either a bug // in older versions, or a regression in newer versions of the typescript completion service. function useReducer R extends Reducer any, any >>( reducer: R , initialState: ReducerState R > , initializer?: undefined ): [ReducerState R > , Dispatch R >>] ; 위의 파일이 제가 현재 사용하고 있는 버전의 useReducer가 정의되어 있는 react의 index.d.ts 파일인데요. 리턴값들을 보시면 첫 번째와 두 번째 정의의 리턴값은 DispatchWithoutAction을 리턴하지만, 나머지 3, 4, 5번째의 리턴값의 dispatch 함수는 Dispatch > 입니다. 이 경우는 action을 받을 수 있는 거 아닌가 생각했는데요. 리액트 노드버드 강좌 들을 때 제 나름대로 타이핑할 때 dispatch 함수에 제네릭을 줬던 기억이 나서 확인해보니 useDispatch는 react-redux의 index.d.ts 파일에 export function useDispatch TDispatch = Dispatch any >>(): TDispatch ; export function useDispatch A extends Action = AnyAction>(): Dispatch A > ; 이렇게 정의되어 있더라고요. useDispatch의 Dispatch 나 위의 useReducer의 Dispatch >이나 마찬가지인 것 같아서 그렇게 사용할 수 있지 않을까 생각했습니다. 그래서 위의 useReducer 타입 정의 중에서 마지막 것에 맞춰보려고 useReducer의 generic을 이래저래 다르게 줘봐도 잘 안 되더라고요. 오버로딩 가능한 것들 중에서 엉뚱한 것을 가져와서 에러가 나는 경우에는 타입을 맞춰보라고 강의 중에 말씀하셨던 것 같은데, 이 경우는 어떻게 해결할 수 있을지 궁금하네요. 감사합니다.
해결했습니다. .eslintrc.js 안에 env 안에 node: true를 설정해주니까 module에 대해서 undefined 뜨던 건 사라졌고, Delete `CR` eslint(prettier/prettier)는 VS code에서 end of line 기본 설정이 LF가 아니라 CRLF로 설정되어 있어서 뜨던 거였네요.