Skip to content

Commit

Permalink
Merge pull request #37 from finsweet/loose-autocomplete
Browse files Browse the repository at this point in the history
Added new `LooseAutocomplete` type
  • Loading branch information
alexiglesias93 authored Jun 13, 2023
2 parents b95095c + 985f85f commit 278d6fe
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/gentle-dots-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@finsweet/ts-utils': minor
---

Added new `LooseAutocomplete` type
17 changes: 15 additions & 2 deletions docs/types.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
prev:
prev:
text: 'Type Guards'
link: '/type-guards'
next:
Expand All @@ -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<MapToConvert>` converts a `Map<K, V>` type to its equivalent when performing `[...map.entries()]`.
Expand Down
12 changes: 12 additions & 0 deletions src/types/LooseAutocomplete.ts
Original file line number Diff line number Diff line change
@@ -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 extends string | number | symbol> = T | Omit<string | number | symbol, T>;
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit 278d6fe

Please sign in to comment.