Skip to content

Commit f90c09b

Browse files
feat(types): autocomplete purpose in IconResource (#616)
* types: autocomplete `purpose` in IconResource * chore: fix string literal union --------- Co-authored-by: userquin <[email protected]>
1 parent 605ce1a commit f90c09b

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/types.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,15 @@ export type Display = 'fullscreen' | 'standalone' | 'minimal-ui' | 'browser'
218218
export type DisplayOverride = Display | 'window-controls-overlay'
219219
export type IconPurpose = 'monochrome' | 'maskable' | 'any'
220220

221+
interface Nothing {}
222+
223+
/**
224+
* type StringLiteralUnion<'maskable'> = 'maskable' | string
225+
* This has auto completion whereas `'maskable' | string` doesn't
226+
* Adapted from https://github.com/microsoft/TypeScript/issues/29729
227+
*/
228+
export type StringLiteralUnion<T extends U, U = string> = T | (U & Nothing)
229+
221230
/**
222231
* @see https://w3c.github.io/manifest/#manifest-image-resources
223232
*/
@@ -228,7 +237,7 @@ export interface IconResource {
228237
/**
229238
* **NOTE**: string values for backward compatibility with the old type.
230239
*/
231-
purpose?: string | IconPurpose | IconPurpose[]
240+
purpose?: StringLiteralUnion<IconPurpose> | IconPurpose[]
232241
}
233242

234243
export interface ManifestOptions {

0 commit comments

Comments
 (0)