diff --git a/packages/@sanity/types/src/schema/define.ts b/packages/@sanity/types/src/schema/define.ts index 84e51f48afed..6abe047c151c 100644 --- a/packages/@sanity/types/src/schema/define.ts +++ b/packages/@sanity/types/src/schema/define.ts @@ -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; @@ -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 | undefined, TPrepareValue extends Record | undefined, @@ -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 | undefined, TPrepareValue extends Record | undefined, @@ -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 | undefined, TPrepareValue extends Record | undefined, diff --git a/packages/@sanity/types/src/schema/types.ts b/packages/@sanity/types/src/schema/types.ts index adcaadd78588..6c80c2165932 100644 --- a/packages/@sanity/types/src/schema/types.ts +++ b/packages/@sanity/types/src/schema/types.ts @@ -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