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

Expand the Identifier type? #2

@adam-rocska

Description

@adam-rocska

Within 21Gram we only use "string" identifiers. Numbers are not ok internally as they open the doors for exploits such as intel guesswork (autoincrements). Instead, we always stick to GUID, UUID, etc. expressed as string ¯_(ツ)_/¯

7gobri

If someone out there in the wilderness would like to have number support, just hit a thumbs up or smthn, we don't have issues with voluntarily shooting yourselves in the foot.

Reminder:

/**
 * @summary Represents the identifier of a REST resource.
 * @description
 * This weirdo type makes sure that the identifier of a
 * REST resource is a `string` but keeps the door open for
 * more strongly typed identifiers.
 * @example
 * The most basic "untyped" string example:
 * ```ts
 * // This is a valid identifier
 * const id: Identifier<string> = 'foo';
 * // This is not a valid identifier
 * const id: Identifier<string> = 42;
 * ```
 * @example
 * A more advanced, typed example:
 * ```ts
 * type ServiceID = 'auth' | 'paymentGateway' | 'cms' | 'crm';
 * // This is a valid identifier
 * const healthCheckId: Identifier<ServiceID> = 'auth';
 * // This is not a valid identifier
 * const healthCheckId: ServiceID = 'foo';
 * ```
 */
export type Identifier<T> = T extends string ? T : never;

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions