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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(ts): cleanup output and use as const and type extraction #411

Open
wants to merge 1 commit into
base: chores/update-typescript-and-other-dependencies
Choose a base branch
from

Conversation

casaper
Copy link
Collaborator

@casaper casaper commented Jun 19, 2022

Typescript constant output typing uses extraction from enum or from the constant (when defined with as const).

Examples:

export enum MyIconsSet {
  Foo = 'foo',
  Bar = 'bar',
}


export type MyIconsSetId = `${MyIconsSet}`;


export const MY_ICONS_SET_CODEPOINTS: readonly { [key in MyIconsSetId]: string } = {
  'foo': '4265',
  'bar': '1231',
} as const;

Or extracting it from the const:

export const MY_ICONS_SET_CODEPOINTS = {
  'foo': '4265',
  'bar': '1231',
} as const;

export type MyIconsSetKey = typeof MY_ICONS_SET_CODEPOINTS[number];

@casaper casaper requested a review from tancredi as a code owner June 19, 2022 23:03
@casaper casaper force-pushed the feat/ts-asset-tipe-modernization branch from 0baf509 to ac51148 Compare June 19, 2022 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant