Skip to content

Make the name type definition explicit (and not just string) #50

@codenomnom

Description

@codenomnom

Summary

As of now, the definition of each status name looks like this:

readonly '100_NAME': string;

Can it be explicit, like:

readonly '100_NAME': 'CONTINUE';

Motivation

The reason for that request is that when we use the name for generic mapping, TS can't properly infer it:

const name = status[`${status.TOO_MANY_REQUESTS}_NAME`];
// its value is indeed "TOO_MANY_REQUESTS"
// but the type is simply "string" (any string)
// which is technically true, and yet cumbersome

// because of that, creating a map doesn't work as best as it could:
const map = {
  [`${status.TOO_MANY_REQUESTS}_NAME`]: 'custom message or something',
}

// IDE cannot figure out that map should contain "TOO_MANY_REQUESTS" key

Alternative

Duplicate names as keys, but that doesn't feel right.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions