Skip to content

Instantly share code, notes, and snippets.

View kenmori's full-sized avatar

KenjiMorita kenmori

View GitHub Profile
@kenmori
kenmori / rewiredしたCRAでTypeScirptのパス解決を相対パスから絶対パスに変更した際のnode_modulesまでbaseUrlになる場合の解決.md
Last active September 13, 2019 02:20
rewiredしたCRAでTypeScirptのパス解決を相対パスから絶対パスに変更した際のnode_modulesまでbaseUrlになる場合の解決「Your project's `baseUrl` can only be set to `src` or `node_modules`. Create React App does not support other values at this time.」

rewiredしたCRAでTypeScirptのパス解決を相対パスから絶対パスに変更した際のnode_modulesまでbaseUrlになる場合の解決

Your project's baseUrl can only be set to src or node_modules. Create React App does not support other values at this time.

To Fix

  • Add src/.env
  • Add src/path.json
@kenmori
kenmori / Separate optional and required types that can have null types.md
Created August 24, 2019 02:55
Separate optional and required types that can have null types

Separate optional and required types that can have null types

type NullAbleType<T> = {[K in keyof T]: T[K] | null}
type Option = { money: number, fn: (...arg: any[])=> void}
type User = {name: string, age: number}
type UserWithOPtionNullAble = User & NullAbleType<Partial<Option>>

// const obj:UserWithOPtionNullAble = {name: "kenji", age: 99, money: 222, fn: ()=>{}}
@kenmori
kenmori / # Type that has null able and optional, but function type is require.md
Last active August 24, 2019 02:16
Type that has null able and optional but function type is require

Type that has null able and optional, but function type is require.

type NullAbleType<T> = {[K in keyof T]: T[K] | null}
type User = {name: string, age: number, money: null, fn: (...arg: any[])=> void}
type FunctionType<T> = {[K in keyof T]: T[K] extends Function? T[K] : never}[keyof T]
type FunctionName = "fun"
type NullAbleUserAndRequireFunction<T> = NullAbleType<Partial<User>> & {[K in T extends FunctionName ? T: never]: FunctionType<User>}

const obj:NullAbleUserAndRequireFunction = {name: null, age: 99, money: null, fun: ()=&gt;{}}
@kenmori
kenmori / 'addEventListener' of undefined.md
Last active August 20, 2019 08:16
jest x material-ui button or tooltips 'addEventListener' of undefined

when test with jest,[material-ui button or tooltips 'addEventListener' of undefined

Error: Uncaught [TypeError: Cannot read property 'addEventListener' of undefined]

console.error node_modules/react-test-renderer/cjs/react-test-renderer.development.js:9215
The above error occurred in the <Connect(OpenDialogIconButton)> component:
in Connect(OpenDialogIconButton) (at ManageApp/index.tsx:373)
in Tooltip (created by WithStyles(Tooltip))
in WithStyles(Tooltip) (at ManageApp/index.tsx:372)
@kenmori
kenmori / 共変性と反変性.md
Last active August 18, 2019 06:54
[TypeSript] 共変性と反変性

WIP

[TypeSript] 共変性と反変性

共変性 と 反変性

Strict function type checking

@kenmori
kenmori / index signature と Recordの空オブジェクトに対する違い.md
Last active August 18, 2019 14:03
[TypeScript] ]index signature と Recordの空オブジェクトに対する違い

[TypeScript] ]index signature と Recordの空オブジェクトに対する違い

twitter

このような型付をみつけて

const a: Record<string, string> = { 
    doorToDoor: "delivery at door",
    airDelivery: "flying in",
@kenmori
kenmori / Jest encountered an unexpected token.md
Created August 14, 2019 04:57
Jest encountered an unexpected token

Jest encountered an unexpected token

FAIL src/components/AuthorityUserSettingItem/index.test.tsx ● Test suite failed to run

Jest encountered an unexpected token

This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.

By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".

@kenmori
kenmori / [解決]failed prop type: Invalid prop `children` supplied to `ForwardRef(Typography)`, expected a ReactNode.md
Last active August 14, 2019 04:34
[解決]failed prop type: Invalid prop `children` supplied to `ForwardRef(Typography)`, expected a ReactNode

[解決]failed prop type: Invalid prop children supplied to ForwardRef(Typography), expected a ReactNode

titleIconElement

////////
<AppList listTitle="タイトル" appInfos={ownAppInfos} showAllUrl={"/apps"} titleIconElement={<></>} />
<AppList listTitle="タイトル" appInfos={favoriteAppInfos} showAllUrl={"/apps/favorite"} titleIconElement={<></>} />
<AppList listTitle="タイトル" appInfos={presetAppInfos} showAllUrl={"/apps/preset"} titleIconElement={<></>} />
@kenmori
kenmori / 【TypeScript】インデックスシグネチャの型定義。string、number.md
Last active September 14, 2019 22:29
【TypeScript】インデックスシグネチャの型定義。string、number

【TypeScript】インデックスシグネチャの型定義。string、number

@bukotsunikki

1.初期化時に指定

let obj:{ [key: string]: string} = {}
@kenmori
kenmori / F-bounded polymorphism.md
Last active August 11, 2019 01:28
F-bounded polymorphism
// ここではそれぞれの型引数(T,U)はお互いの関係性は知らない
function someFunction <T, U> (t: T, u: U): T {
  return t;
}

const dog = someFunction(new Dog(), new Cat());

// これを `T extends U` とすることで第二引数のU型を制約とするTになった
function someFunction  (t: T, u: U): T {