Skip to content

Commit

Permalink
feat(types): autocomplete purpose in IconResource (#616)
Browse files Browse the repository at this point in the history
* types: autocomplete `purpose` in IconResource

* chore: fix string literal union

---------

Co-authored-by: userquin <userquin@gmail.com>
  • Loading branch information
DamianGlowala and userquin committed Dec 6, 2023
1 parent 605ce1a commit f90c09b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 extends U, U = string> = T | (U & Nothing)

/**
* @see https://w3c.github.io/manifest/#manifest-image-resources
*/
Expand All @@ -228,7 +237,7 @@ export interface IconResource {
/**
* **NOTE**: string values for backward compatibility with the old type.
*/
purpose?: string | IconPurpose | IconPurpose[]
purpose?: StringLiteralUnion<IconPurpose> | IconPurpose[]
}

export interface ManifestOptions {
Expand Down

0 comments on commit f90c09b

Please sign in to comment.