Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

Support const assertions equivalent #317

Open
amatiasq opened this issue Dec 3, 2020 · 0 comments
Open

Support const assertions equivalent #317

amatiasq opened this issue Dec 3, 2020 · 0 comments
Assignees
Labels
duplicate This issue or pull request already exists enhancement New feature or request

Comments

@amatiasq
Copy link

amatiasq commented Dec 3, 2020

TypeScript has this feature called "const assertions" where we can ask the type system to interpret the values as literal (1, "test", true...) instead of their type (number, string and boolean respectively).

This avoids code duplication:

const foo = {
  test: 1,
  bar: "quz",
} as const;

type FooType = typeof foo;

/*
type FooType = {
    readonly test: 1;
    readonly bar: "quz";
}
*/

TS Playground

Related to #186

@amatiasq amatiasq changed the title Support constant assertions equivalent Support const assertions equivalent Dec 3, 2020
@JSMonk JSMonk added duplicate This issue or pull request already exists enhancement New feature or request labels Dec 5, 2020
@JSMonk JSMonk self-assigned this Dec 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate This issue or pull request already exists enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants