Created
April 27, 2021 09:34
-
-
Save ashimon83/9416923596c6793307b5ca6c409297db to your computer and use it in GitHub Desktop.
tsでenumっぽいの扱うやり方
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const SomeStatus = { | |
REQUESTED: '申請', | |
DONE: '完了', | |
REJECT: '差し戻し', | |
} as const; | |
export type SomeStatusType = keyof typeof SomeStatus; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { SomeStatus, SomeStatusType } from 'some-status' | |
interface Props { | |
status: SomeStatusType | |
} | |
const SomeComponent: React.FC<Props> = ({status = 'REQUESTED'}) => { | |
return ( | |
<div>status: {SomeStatus[status]}</div> | |
) | |
} | |
// <div>status: 申請</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment