Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[colors] Add TypeScript interface for color constants #30390

Open
2 tasks done
acroyear opened this issue Dec 24, 2021 · 2 comments
Open
2 tasks done

[colors] Add TypeScript interface for color constants #30390

acroyear opened this issue Dec 24, 2021 · 2 comments

Comments

@acroyear
Copy link
Contributor

acroyear commented Dec 24, 2021

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Summary 馃挕

Currently the files for the constants like "amber" are simply declare const amber: { 50: ..., ...etc }. This means they don't have an actual common type I can pass into a function or get back from a function. It would be great if there was an interface for the object to make it easier to make such declarations (just doing "typeof amber" doesn't auto-apply to the other constants like blue). Something like

interface MaterialStandardColorShades {
  50: string;
  100: string;
  200: string;
  300: string;
  400: string;
  500: string;
  600: string;
  700: string;
  800: string;
  900: string;
  A100: string;
  A200: string;
  A400: string;
  A700: string;
  [key: string | number]: string;
};

Examples 馃寛

No response

Motivation 馃敠

Trying to make a color picker type of thing, passing in the constants with keys and getting the full values back from the selector object. Until I added the above interface, I was forced to things which I'd prefer to avoid.

@acroyear acroyear added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Dec 24, 2021
@acroyear
Copy link
Contributor Author

Workaround: that interface in the summary works, and the colors will auto-match to it, so just add that to your own project.

@acroyear
Copy link
Contributor Author

Updated the key - it'll take both string and number to support amber[500] as well as amber['500']. amber[500] === amber['500'] returned true as expected/hoped.

@mbrookes mbrookes changed the title add interface for color constants (amber, etc...) [colors] Add TypeScript interface for color constants Dec 26, 2021
@mbrookes mbrookes added typescript and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Dec 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants