Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSSProperties TextAlignProperty type error

I'm using React 16.8 with Typescript "@zeit/next-typescript": "1.1.0"

I have inline-style interface. And There is object using IInputInlineStyle interface.

interface IInputInlineStyle {
    padding: string;
    textAlign?: string;
    paddingLeft?: string | number;
    color?: string;
}

 const inputInlineStyle: IInputInlineStyle = {
            padding,
            textAlign
        };

But I got this error message.

Error:(155, 21) TS2322: Type 'IInputInlineStyle' is not assignable to type 'CSSProperties'.

Types of property 'textAlign' are incompatible.

Type 'string' is not assignable to type 'TextAlignProperty'.

How can I fix this problem?

like image 211
kkangil Avatar asked Jul 13 '26 00:07

kkangil


1 Answers

Since Typescript 3.4 you can make use of the as const notation:

const inputInlineStyle = {
  textAlign: 'center' as const
};

Source - https://github.com/typestyle/typestyle/issues/281#issuecomment-535359254

like image 77
Oyedeji Peace Avatar answered Jul 14 '26 13:07

Oyedeji Peace



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!