Type 'string' is not assignable to type 'WebkitAppearance | undefined' in React + TypeScript?

Viewed 170

I see that you do it like <div style={{WebkitAppearance: SOMETHING}}></div>, but what is SOMETHING?

type PropType = {
  appearance: string;
}

function MyComponent({
  appearance
}: PropType) {
  const style = {
    WebkitAppearance: appearance
  }
}

I am getting this error:

Type 'string' is not assignable to type 'WebkitAppearance | undefined'

How do you set -webkit-appearance in React + TypeScript?

1 Answers

"SOMETHING" is the Property.WebkitAppearance type from csstype.


Instead of WebkitAppearance, you probably want to use appearance, which is the standard property. Only use WebkitAppearance if you are setting it to a non-standard value, like "attachment".

Note that neither of these are assignable to string (thus your error); you must use their types defined in the csstype package:

import { Property } from './node_modules/csstype';

type PropType = {
  appearance: Property.WebkitAppearance;
}

Playground examples

Related