diff --git a/packages/lex-cli/src/codegen/client.ts b/packages/lex-cli/src/codegen/client.ts index eee06071277..d7e916ced9a 100644 --- a/packages/lex-cli/src/codegen/client.ts +++ b/packages/lex-cli/src/codegen/client.ts @@ -312,7 +312,7 @@ function genRecordCls(file: SourceFile, nsid: string, lexRecord: LexRecord) { }) method.addParameter({ name: 'params', - type: `Omit<${toTitleCase(ATP_METHODS.list)}.QueryParams, "collection">`, + type: `StrictKeyOmit<${toTitleCase(ATP_METHODS.list)}.QueryParams, "collection">`, }) method.setBodyText( [ @@ -330,7 +330,7 @@ function genRecordCls(file: SourceFile, nsid: string, lexRecord: LexRecord) { }) method.addParameter({ name: 'params', - type: `Omit<${toTitleCase(ATP_METHODS.get)}.QueryParams, "collection">`, + type: `StrictKeyOmit<${toTitleCase(ATP_METHODS.get)}.QueryParams, "collection">`, }) method.setBodyText( [ @@ -348,7 +348,7 @@ function genRecordCls(file: SourceFile, nsid: string, lexRecord: LexRecord) { }) method.addParameter({ name: 'params', - type: `Omit<${toTitleCase( + type: `StrictKeyOmit<${toTitleCase( ATP_METHODS.create, )}.InputSchema, "collection" | "record">`, }) @@ -380,7 +380,7 @@ function genRecordCls(file: SourceFile, nsid: string, lexRecord: LexRecord) { // }) // method.addParameter({ // name: 'params', - // type: `Omit<${toTitleCase(ATP_METHODS.put)}.InputSchema, "collection" | "record">`, + // type: `StrictKeyOmit<${toTitleCase(ATP_METHODS.put)}.InputSchema, "collection" | "record">`, // }) // method.addParameter({ // name: 'record', @@ -407,7 +407,7 @@ function genRecordCls(file: SourceFile, nsid: string, lexRecord: LexRecord) { }) method.addParameter({ name: 'params', - type: `Omit<${toTitleCase( + type: `StrictKeyOmit<${toTitleCase( ATP_METHODS.delete, )}.InputSchema, "collection">`, }) @@ -444,6 +444,7 @@ const lexiconTs = (project, lexicons: Lexicons, lexiconDoc: LexiconDoc) => xrpcImport.addNamedImports([ { name: 'HeadersMap' }, { name: 'XRPCError' }, + { name: 'StrictKeyOmit' }, ]) } //= import {ValidationResult, BlobRef} from '@atproto/lexicon' diff --git a/packages/xrpc/src/types.ts b/packages/xrpc/src/types.ts index 11e88445271..0ed3e12a408 100644 --- a/packages/xrpc/src/types.ts +++ b/packages/xrpc/src/types.ts @@ -188,3 +188,17 @@ export class XRPCInvalidResponseError extends XRPCError { ) } } + +type IsLiteralKey = { + string: string extends K ? 0 : 1 + number: number extends K ? 0 : 1 + symbol: symbol extends K ? 0 : 1 +}[K extends string ? 'string' : K extends number ? 'number' : 'symbol'] + +type LiteralKey = keyof { + [K in keyof T as IsLiteralKey extends 1 ? K : never]: K +} + +export type StrictKeyOmit> = { + [K2 in keyof T as K2 extends K ? never : K2]: T[K2] +}