Skip to content

Instantly share code, notes, and snippets.

@ashimon83
Created April 27, 2021 09:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashimon83/9416923596c6793307b5ca6c409297db to your computer and use it in GitHub Desktop.
Save ashimon83/9416923596c6793307b5ca6c409297db to your computer and use it in GitHub Desktop.
tsでenumっぽいの扱うやり方
export const SomeStatus = {
REQUESTED: '申請',
DONE: '完了',
REJECT: '差し戻し',
} as const;
export type SomeStatusType = keyof typeof SomeStatus;
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