Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is-mobile判定の追加とstyled componentへのprops渡し #119

Closed
wants to merge 5 commits into from

Conversation

spaspa
Copy link
Member

@spaspa spaspa commented Mar 5, 2020

型が複雑になったりシンタックスハイライトが効かなかったりしますが……

@spaspa spaspa requested a review from unipota March 5, 2020 07:11
@sapphi-red
Copy link
Contributor

sapphi-red commented Mar 5, 2020

type Primitify<T> = T extends String
  ? string
  : T extends Number
  ? number
  : T extends Boolean
  ? boolean
  : T extends BigInt
  ? bigint
  : T extends Symbol
  ? symbol
  : T
  //: T extends Object
  //? Record<string, any>
  //: never


type Constructorize<T> = ObjectConstructor & {
  new (): T
}

const HeaderProps = { poyo: Object as Constructorize<{ a: boolean }> }

const Header = styled('h1', HeaderProps)`
  font: {
    size: 30px;
    weight: bold;
  }
  color: ${theme.accent.primary};
  background-color: ${props => (props.poyo.a ? 'red' : 'blue')};
`

型の実体と宣言が微妙にずれるんですがこんな感じにするとprops.poyo.aに型つけれました

Arrayも似たような感じでできるかもしれないです

@spaspa
Copy link
Member Author

spaspa commented Mar 5, 2020

なるほど、new()で返せば良いのか
基本プリミティブでやって、どうしてもオブジェクト使いたい時はこうしていく感じにしますか

@spaspa
Copy link
Member Author

spaspa commented Mar 7, 2020

胡蝶の夢を見ていたようなので閉じます

@spaspa spaspa closed this Mar 7, 2020
@sapphi-red sapphi-red deleted the feat/media-query branch July 23, 2021 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants