I use this approach for style in my vue ts project.
private styleTableObject: CSSStyleSheet = {
width: '100%',
height: '76%'
}
I am forced to the any
type.
private styleTableObject: any = {
width: '100%',
height: '76%'
}
Error logs:
Type '{ width: string; height: string; }' is not assignable to type 'CSSStyleSheet'.
Object literal may only specify known properties, and 'width' does not exist in type 'CSSStyleSheet'.
If a use any type from visual code helper i got error logs:
Type '{ width: string; height: string; }' is not assignable to type 'StyleSheet'.
Object literal may only specify known properties, and 'width' does not exist in type 'StyleSheet'.
219:13 Type '{ width: string; height: string; }' is missing the following properties from type 'CSSStyleDeclaration': alignContent, alignItems, alignSelf, alignmentBaseline, and 382 more.
Use Partial<CSSStyleDeclaration>
instead
Partial<T>
Constructs a type with all properties of T set to optional. This utility will return a type that represents all subsets of a given type
From: https://www.typescriptlang.org/docs/handbook/utility-types.html#partialt
So your code will look like this
private styleTableObject: Partial<CSSStyleDeclaration> = {
width: '100%',
height: '76%'
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With