Skip to content

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.

1 participant