打字稿的 CSS 接口

时间:2020-12-19 14:58:02

标签: css typescript interface

打字稿中是否有任何 CSS 接口? 我想定义我的接口来扩展它...... 像这样:

export interface IComponentProperties extends ICSS {
    title: string,    
    text?: string,  
    resizable?: boolean,
    connectToParent?:  string | HTMLElement,
    replaceParentContent?: boolean,
}

没有任何 css 界面,我的界面应该是这样的:

export interface IComponentProperties{
    // CSS props
    width?: string,
    height?: string,
    backgroundColor?: string,
    display?: string,
    position?: string,
    left?: string,
    right?: string,
    transition?: string,
    "z-index"?: string,
    "flex-direction"?: string,

    // Component props
    title: string,    
    text?: string,  
    resizable?: boolean,
    connectToParent?:  string | HTMLElement,
    replaceParentContent?: boolean,
}

而且我必须在那里指定每个 css 属性,我最终会使用这些属性... 那么有没有我可以扩展的 CSS 接口?

谢谢!

1 个答案:

答案 0 :(得分:1)

存在keycloakConfig = { realm: 'test-realm', authServerUrl: 'https://myurl/auth/', realmPublicKey: 'key' }; ,但请注意,当属性值不存在时,会给出空字符串而不是CSSStyleDeclaration

undefined

所以你需要使用部分:

const { style } = document.createElement('div');
console.log(style.height, typeof style.height, style.height.length);

另请注意,您需要使用 interface MyStyle extends Partial<CSSStyleDeclaration> { title: string; text?: string; } const s: MyStyle = { title: 'foo', }; zIndex 属性,而不是 flexDirectionz-index