Skip to content

types: autocomplete purpose in IconResource #616

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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