diff --git a/.changeset/gentle-dots-jump.md b/.changeset/gentle-dots-jump.md new file mode 100644 index 0000000..450c490 --- /dev/null +++ b/.changeset/gentle-dots-jump.md @@ -0,0 +1,5 @@ +--- +'@finsweet/ts-utils': minor +--- + +Added new `LooseAutocomplete` type diff --git a/docs/types.md b/docs/types.md index 13e1ef5..9b76d82 100644 --- a/docs/types.md +++ b/docs/types.md @@ -1,5 +1,5 @@ --- -prev: +prev: text: 'Type Guards' link: '/type-guards' next: @@ -9,11 +9,24 @@ next: # Types - ## `FormField` `FormField` is the Form Field element on Webflow +## `LooseAutocomplete` + +A type that allows for variable autocompletion with loose validation. + +Example: + +```typescript +const f = (foo: LooseAutocomplete<'a' | 'b'>) => foo; +f(''); // VSCode autocomplete shows 'a' and 'b' as options, but doesn't fail when a different option is provided. +f('a'); // Valid +f('b'); // Valid +f('c'); // Valid +``` + ## `MapEntries` `MapEntries` converts a `Map` type to its equivalent when performing `[...map.entries()]`. diff --git a/src/types/LooseAutocomplete.ts b/src/types/LooseAutocomplete.ts new file mode 100644 index 0000000..b214e78 --- /dev/null +++ b/src/types/LooseAutocomplete.ts @@ -0,0 +1,12 @@ +/** + * A type that allows for variable autocompletion with loose validation. + * @example + * ```typescript + * const f = (foo: LooseAutocomplete<'a' | 'b'>) => foo; + * f(''); // VSCode autocomplete shows 'a' and 'b' as options, but doesn't fail when a different option is provided. + * f('a'); // Valid + * f('b'); // Valid + * f('c'); // Valid + * ``` + */ +export type LooseAutocomplete = T | Omit; diff --git a/src/types/index.ts b/src/types/index.ts index 440a21e..fb478bb 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -2,6 +2,7 @@ export * as Greenhouse from './apis/Greenhouse'; export type { Entry } from './Entry'; export type { FormField } from './FormField'; export type { Instance } from './Instance'; +export type { LooseAutocomplete } from './LooseAutocomplete'; export type { MapEntries } from './MapEntries'; export type { PartialExcept } from './PartialExcept'; export type { PickPartial } from './PickPartial';