question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CSS custom properties

See original GitHub issue

I am writing an app in React and Typescript and will be making heavy use of CSS custom properties.

Could you idiot-proof the documentation a bit more please? Is css.d.ts a file I need to create and does it matter what directory it is in?

// My css.d.ts file
import * as CSS from 'csstype';

declare module 'csstype' {
  interface Properties {
    // Add a missing property
    WebkitRocketLauncher?: string;

    // Add a CSS Custom Property
    '--theme-color'?: 'black' | 'white';

    // ...or allow any other property
    [index: string]: any;
  }
}

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:9
  • Comments:15 (3 by maintainers)

github_iconTop GitHub Comments

10reactions
mohsen1commented, Jul 30, 2021

TypeScript 4.4 does allow specifying types for properties with a pattern. In this case you can specify something like this:

interface CSSProperties {
  // ... all other properties
  [variableName: `--${string}`]: any;
}
7reactions
yordiscommented, Feb 25, 2019

I will recommend you to do the following strategy.

import * as React from 'react';

export interface AppStyle extends React.CSSProperties {
  '--app-background-color': string;
  '--app-color': string;
}

export const App: React.FunctionComponent<IAppProp> = props => {
  const style: AppStyle = {
    '--app-background-color': props.backgroundColor,
    '--app-color': props.color,
  };

  return (
    <div style={style}></div>
  );
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom properties (--*): CSS variables - MDN Web Docs
Custom properties are scoped to the element(s) they are declared on, and participate in the cascade: the value of such a custom property...
Read more >
A Complete Guide to Custom Properties | CSS-Tricks
Custom properties are different than preprocessor variables · Native CSS custom properties are more powerful then preprocessor variables. · Native ...
Read more >
CSS Custom Properties for Cascading Variables Module Level 1
Custom properties are ordinary properties, so they can be declared on any element, are resolved with the normal inheritance and cascade rules, ...
Read more >
A Strategy Guide To CSS Custom Properties
CSS Custom Properties are by default locally scoped to the specific selectors we apply them to. So they are kinda like local variables....
Read more >
CSS Custom Properties (CSS Variables) Sample
CSS custom properties allow you to store and retrieve values from properties you define yourself. They follow the same rules as other CSS...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found