Skip to content

Commit

Permalink
fix: add tsdoc comment; add to defineField and defineArrayMember
Browse files Browse the repository at this point in the history
  • Loading branch information
ricokahler committed Apr 22, 2024
1 parent bad81d3 commit 0333907
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
8 changes: 4 additions & 4 deletions packages/@sanity/types/src/schema/define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
type WidenValidation,
} from './defineTypes'
import {type FieldDefinitionBase, type IntrinsicTypeName} from './definition'
import {type AllowOtherStrings} from './types'
import {type AutocompleteString} from './types'

/**
* Helper function for defining a Sanity type definition. This function does not do anything on its own;
Expand Down Expand Up @@ -171,7 +171,7 @@ import {type AllowOtherStrings} from './types'
* @beta
*/
export function defineType<
const TType extends IntrinsicTypeName | AllowOtherStrings,
const TType extends IntrinsicTypeName | AutocompleteString,
const TName extends string,
TSelect extends Record<string, string> | undefined,
TPrepareValue extends Record<keyof TSelect, any> | undefined,
Expand Down Expand Up @@ -212,7 +212,7 @@ export function defineType<
* @beta
*/
export function defineField<
const TType extends string | IntrinsicTypeName, // IntrinsicTypeName here improves autocompletion in _some_ IDEs (not VS Code atm)
const TType extends IntrinsicTypeName | AutocompleteString,
const TName extends string,
TSelect extends Record<string, string> | undefined,
TPrepareValue extends Record<keyof TSelect, any> | undefined,
Expand Down Expand Up @@ -255,7 +255,7 @@ export function defineField<
* @beta
*/
export function defineArrayMember<
const TType extends string | IntrinsicTypeName, // IntrinsicTypeName here improves autocompletion in _some_ IDEs (not VS Code atm)
const TType extends IntrinsicTypeName | AutocompleteString,
const TName extends string,
TSelect extends Record<string, string> | undefined,
TPrepareValue extends Record<keyof TSelect, any> | undefined,
Expand Down
15 changes: 13 additions & 2 deletions packages/@sanity/types/src/schema/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,20 @@ import {type PreviewConfig} from './preview'

export {defineArrayMember, defineField, defineType, typed} from './define'

// Necessary since this is the only way to include all string literals and all other strings
/**
* Enhances VSCode autocomplete by using a distinct type for strings.
*
* `AllowOtherStrings` is defined as `string & {}`, an intersection that behaves
* like `string` but is treated differently by TypeScript's type system for
* internal processing. This helps in improving the specificity and relevance of
* autocomplete suggestions by potentially prioritizing `IntrinsicTypeName`
* over general string inputs, addressing issues where `string` type suggestions
* might overshadow more useful specific literals.
*
* @beta
*/
// eslint-disable-next-line @typescript-eslint/ban-types
export type AllowOtherStrings = string & {}
export type AutocompleteString = string & {}

/**
* Note: you probably want `SchemaTypeDefinition` instead
Expand Down

0 comments on commit 0333907

Please sign in to comment.