Skip to content

Commit

Permalink
fix(core): upgrade and fix types for typescript 5.4 (#5943)
Browse files Browse the repository at this point in the history
  • Loading branch information
ricokahler authored Mar 11, 2024
1 parent 4e95e09 commit 4e72b80
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 78 deletions.
2 changes: 1 addition & 1 deletion dev/embedded-studio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@types/react": "^18.2.37",
"@types/react-dom": "^18.2.15",
"@vitejs/plugin-react": "^4.2.1",
"typescript": "^5.2.2",
"typescript": "^5.4.2",
"vite": "^4.5.1"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
"sanity": "workspace:*",
"semver": "^7.3.5",
"turbo": "^1.12.4",
"typescript": "^5.2.2",
"typescript": "^5.4.2",
"yargs": "^17.3.0"
},
"optionalDependencies": {
Expand Down
18 changes: 10 additions & 8 deletions packages/@sanity/types/src/schema/define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ import {type FieldDefinitionBase, type IntrinsicTypeName} from './definition'
* @beta
*/
export function defineType<
TType extends string | IntrinsicTypeName, // IntrinsicTypeName here improves autocompletion in _some_ IDEs (not VS Code atm)
TName extends string,
const TType extends string | IntrinsicTypeName, // IntrinsicTypeName here improves autocompletion in _some_ IDEs (not VS Code atm)
const TName extends string,
TSelect extends Record<string, string> | undefined,
TPrepareValue extends Record<keyof TSelect, any> | undefined,
TAlias extends IntrinsicTypeName | undefined,
Expand Down Expand Up @@ -211,8 +211,8 @@ export function defineType<
* @beta
*/
export function defineField<
TType extends string | IntrinsicTypeName, // IntrinsicTypeName here improves autocompletion in _some_ IDEs (not VS Code atm)
TName extends string,
const TType extends string | IntrinsicTypeName, // IntrinsicTypeName here improves autocompletion in _some_ IDEs (not VS Code atm)
const TName extends string,
TSelect extends Record<string, string> | undefined,
TPrepareValue extends Record<keyof TSelect, any> | undefined,
TAlias extends IntrinsicTypeName | undefined,
Expand All @@ -229,7 +229,8 @@ export function defineField<
// eslint-disable-next-line @typescript-eslint/no-unused-vars
defineOptions?: DefineSchemaOptions<TStrict, TAlias>,
): typeof schemaField & WidenValidation & WidenInitialValue {
return schemaField
// TODO: re-evaluate the need for this cast
return schemaField as typeof schemaField & WidenValidation & WidenInitialValue
}

/**
Expand All @@ -253,8 +254,8 @@ export function defineField<
* @beta
*/
export function defineArrayMember<
TType extends string | IntrinsicTypeName, // IntrinsicTypeName here improves autocompletion in _some_ IDEs (not VS Code atm)
TName extends string,
const TType extends string | IntrinsicTypeName, // IntrinsicTypeName here improves autocompletion in _some_ IDEs (not VS Code atm)
const TName extends string,
TSelect extends Record<string, string> | undefined,
TPrepareValue extends Record<keyof TSelect, any> | undefined,
TAlias extends IntrinsicTypeName | undefined,
Expand All @@ -276,7 +277,8 @@ export function defineArrayMember<
// eslint-disable-next-line @typescript-eslint/no-unused-vars
defineOptions?: DefineSchemaOptions<TStrict, TAlias>,
): typeof arrayOfSchema & WidenValidation & WidenInitialValue {
return arrayOfSchema
// TODO: re-evaluate the need for this cast
return arrayOfSchema as typeof arrayOfSchema & WidenValidation & WidenInitialValue
}

/**
Expand Down
4 changes: 1 addition & 3 deletions packages/@sanity/types/src/schema/test/alias.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {describe, it} from '@jest/globals'

/* eslint-disable @typescript-eslint/no-unused-vars */
/**
* Some of these tests have no expect statement;
Expand Down Expand Up @@ -94,7 +95,6 @@ describe('alias type test', () => {
})

it('should support alias with preview', () => {
//@ts-expect-error {error: any} has no properties in common with PreviewValue
defineType({
type: 'custom-object',
name: 'redefined',
Expand All @@ -105,7 +105,6 @@ describe('alias type test', () => {
},
})

//@ts-expect-error {error: any} has no properties in common with PreviewValue
defineField({
type: 'custom-object',
name: 'redefined',
Expand All @@ -116,7 +115,6 @@ describe('alias type test', () => {
},
})

//@ts-expect-error {error: any} has no properties in common with PreviewValue
defineArrayMember({
type: 'custom-object',
name: 'redefined',
Expand Down
2 changes: 1 addition & 1 deletion perf/tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@types/node": "^18.15.3",
"esbuild": "^0.19.8",
"ts-node": "^10.9.1",
"typescript": "^5.2.2"
"typescript": "^5.4.2"
},
"dependencies": {
"@playwright/test": "^1.41.2",
Expand Down
Loading

0 comments on commit 4e72b80

Please sign in to comment.