From f90c09bad74d025c4608a2b9dfd5c79d5079ca7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20G=C5=82owala?= Date: Wed, 6 Dec 2023 13:04:57 +0100 Subject: [PATCH] feat(types): autocomplete `purpose` in IconResource (#616) * types: autocomplete `purpose` in IconResource * chore: fix string literal union --------- Co-authored-by: userquin --- src/types.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/types.ts b/src/types.ts index 9eaba499..9036235b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -218,6 +218,15 @@ export type Display = 'fullscreen' | 'standalone' | 'minimal-ui' | 'browser' export type DisplayOverride = Display | 'window-controls-overlay' export type IconPurpose = 'monochrome' | 'maskable' | 'any' +interface Nothing {} + +/** + * type StringLiteralUnion<'maskable'> = 'maskable' | string + * This has auto completion whereas `'maskable' | string` doesn't + * Adapted from https://github.com/microsoft/TypeScript/issues/29729 + */ +export type StringLiteralUnion = T | (U & Nothing) + /** * @see https://w3c.github.io/manifest/#manifest-image-resources */ @@ -228,7 +237,7 @@ export interface IconResource { /** * **NOTE**: string values for backward compatibility with the old type. */ - purpose?: string | IconPurpose | IconPurpose[] + purpose?: StringLiteralUnion | IconPurpose[] } export interface ManifestOptions {