From c72e72ad038bb436287b984a98ad7eb992664be6 Mon Sep 17 00:00:00 2001 From: "Aaron S." <94858815+stocaaro@users.noreply.github.com> Date: Wed, 4 Dec 2024 16:01:08 -0600 Subject: [PATCH] fix: Typescript errors (#14037) * fix: Typescript errors * Fix test errors --- packages/api-graphql/src/internals/v6.ts | 4 +++- packages/api-graphql/src/types/index.ts | 2 +- packages/datastore/src/types.ts | 12 ++++++++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/api-graphql/src/internals/v6.ts b/packages/api-graphql/src/internals/v6.ts index c5d362908c8..553707be092 100644 --- a/packages/api-graphql/src/internals/v6.ts +++ b/packages/api-graphql/src/internals/v6.ts @@ -4,6 +4,7 @@ import { CustomHeaders } from '@aws-amplify/data-schema/runtime'; import { GraphQLAPI } from '../GraphQLAPI'; import { + GraphQLOptions, GraphQLOptionsV6, GraphQLResponseV6, V6Client, @@ -113,10 +114,11 @@ export function graphql< * Neither of these can actually be validated at runtime. Hence, we don't perform * any validation or type-guarding here. */ + const result = GraphQLAPI.graphql( // TODO: move V6Client back into this package? internals.amplify as any, - options, + options as GraphQLOptions, headers, ); diff --git a/packages/api-graphql/src/types/index.ts b/packages/api-graphql/src/types/index.ts index 0ecac34369a..d642fff3bd1 100644 --- a/packages/api-graphql/src/types/index.ts +++ b/packages/api-graphql/src/types/index.ts @@ -212,7 +212,7 @@ export type GraphQLOperation = Source | string; export interface GraphQLOptionsV6< FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string, -> { +> extends Record { query: TYPED_GQL_STRING | DocumentNode; variables?: GraphQLVariablesV6; authMode?: GraphQLAuthMode; diff --git a/packages/datastore/src/types.ts b/packages/datastore/src/types.ts index abc92322cc7..a36cad59ca1 100644 --- a/packages/datastore/src/types.ts +++ b/packages/datastore/src/types.ts @@ -506,6 +506,10 @@ export type TypeConstructorMap = Record< export declare const __identifierBrand__: unique symbol; export type IdentifierBrand = T & { [__identifierBrand__]: K }; +interface GenericIdentifier { + field: any; +} + // datastore generates a uuid for you export type ManagedIdentifier = IdentifierBrand< { field: F extends string ? F : never; type: T }, @@ -548,7 +552,9 @@ export type IdentifierFields< infer B > ? B[number] // B[number] - : MetadataOrDefault['identifier']['field']) & + : MetadataOrDefault['identifier'] extends GenericIdentifier + ? MetadataOrDefault['identifier']['field'] + : unknown) & string; export type IdentifierFieldsForInit< @@ -710,7 +716,9 @@ export type IdentifierFieldValue< ? MetadataOrDefault['identifier']['fields'] extends [any] ? T[MetadataOrDefault['identifier']['fields'][0]] : never - : T[MetadataOrDefault['identifier']['field']]; + : MetadataOrDefault['identifier'] extends GenericIdentifier + ? T[MetadataOrDefault['identifier']['field']] + : unknown; export type IdentifierFieldOrIdentifierObject< T extends PersistentModel,