diff --git a/packages/legacy-client/changelog/@unreleased/pr-23.v2.yml b/packages/legacy-client/changelog/@unreleased/pr-23.v2.yml new file mode 100644 index 000000000..34e44cd06 --- /dev/null +++ b/packages/legacy-client/changelog/@unreleased/pr-23.v2.yml @@ -0,0 +1,5 @@ +type: fix +fix: + description: action params type fix + links: + - https://github.com/palantir/osdk-ts/pull/23 diff --git a/packages/legacy-client/src/client/actions/actions.test.ts b/packages/legacy-client/src/client/actions/actions.test.ts index d73b89fc8..a96619d81 100644 --- a/packages/legacy-client/src/client/actions/actions.test.ts +++ b/packages/legacy-client/src/client/actions/actions.test.ts @@ -32,14 +32,13 @@ import { it, vi, } from "vitest"; -import { - type ActionError, - ActionExecutionMode, - type ActionExecutionOptions, - type ActionResponseFromOptions, - type Edits, - type Result, - ReturnEditsMode, +import { ActionExecutionMode, ReturnEditsMode } from "../.."; +import type { + ActionError, + ActionExecutionOptions, + ActionResponseFromOptions, + Edits, + Result, } from "../.."; import { USER_AGENT } from "../../USER_AGENT"; import { @@ -49,7 +48,7 @@ import { import { unwrapResultOrThrow } from "../../util/test/resultUtils"; import { createBaseOsdkObjectSet } from "../objectSets/OsdkObjectSet"; import type { OsdkLegacyObjectFrom } from "../OsdkLegacyObject"; -import { type Actions } from "./actions"; +import type { Actions } from "./actions"; import { createActionProxy } from "./createActionProxy"; describe("Actions", () => { @@ -73,7 +72,7 @@ describe("Actions", () => { describe("type tests", () => { it("creates proper parameters", async () => { - expectTypeOf>().toMatchTypeOf< + expectTypeOf>().toEqualTypeOf< [ { id?: number; @@ -82,6 +81,10 @@ describe("Actions", () => { ] >(); + expectTypeOf() + // @ts-expect-error + .toBeCallableWith([{ id: 1 }]); + expectTypeOf>().toMatchTypeOf< Promise< Result< diff --git a/packages/legacy-client/src/client/actions/actions.ts b/packages/legacy-client/src/client/actions/actions.ts index 04bf08509..33e3a8015 100644 --- a/packages/legacy-client/src/client/actions/actions.ts +++ b/packages/legacy-client/src/client/actions/actions.ts @@ -46,20 +46,23 @@ export type ActionArgs< O extends OntologyDefinition, A extends keyof O["actions"], > = - & { - [P in NullableKeys]?: ActionParameterType< - O, - A, - P - >; - } - & { - [P in NonNullableKeys]: ActionParameterType< - O, - A, - P - >; - }; + & (NonNullableKeys extends never ? {} + : { + [P in NonNullableKeys]: + ActionParameterType< + O, + A, + P + >; + }) + & (NullableKeys extends never ? {} + : { + [P in NullableKeys]?: ActionParameterType< + O, + A, + P + >; + }); export type ActionParameterType< O extends OntologyDefinition, diff --git a/packages/legacy-client/src/client/queries.test.ts b/packages/legacy-client/src/client/queries.test.ts index 8bb853f3a..f57df4818 100644 --- a/packages/legacy-client/src/client/queries.test.ts +++ b/packages/legacy-client/src/client/queries.test.ts @@ -333,6 +333,18 @@ describe("Queries", () => { LocalDate >; }]>(); + + expectTypeOf< + Parameters["queryWithOnlyOptionalArgs"]> + >().toEqualTypeOf<[{ string?: string }]>(); + + expectTypeOf< + Parameters["queryWithOnlyRequiredArgs"]> + >().toEqualTypeOf<[{ string: string }]>(); + + expectTypeOf() + // @ts-expect-error + .toBeCallableWith([{ string: "test" }]); }); }); @@ -344,6 +356,8 @@ describe("Queries", () => { "queryReturnsAggregation", "queryTakesAllParameterTypes", "queryTakesNestedObjects", + "queryWithOnlyOptionalArgs", + "queryWithOnlyRequiredArgs", ] `); }); diff --git a/packages/legacy-client/src/client/queries.ts b/packages/legacy-client/src/client/queries.ts index 0bd97d750..4d99d2e02 100644 --- a/packages/legacy-client/src/client/queries.ts +++ b/packages/legacy-client/src/client/queries.ts @@ -83,20 +83,20 @@ export type QueryArgs< O extends OntologyDefinition, Q extends QueryNamesFrom, > = - & { + & (NonNullableArgKeys> extends never ? {} : { [P in NonNullableArgKeys>]: QueryDataType< O, QueryParameters[P], false >; - } - & { + }) + & (NullableArgKeys> extends never ? {} : { [P in NullableArgKeys>]?: QueryDataType< O, QueryParameters[P], false >; - }; + }); export type QueryNamesFrom> = keyof O["queries"]; diff --git a/packages/shared.test/changelog/@unreleased/pr-23.v2.yml b/packages/shared.test/changelog/@unreleased/pr-23.v2.yml new file mode 100644 index 000000000..34e44cd06 --- /dev/null +++ b/packages/shared.test/changelog/@unreleased/pr-23.v2.yml @@ -0,0 +1,5 @@ +type: fix +fix: + description: action params type fix + links: + - https://github.com/palantir/osdk-ts/pull/23 diff --git a/packages/shared.test/src/mock-ontology/mockOntology.ts b/packages/shared.test/src/mock-ontology/mockOntology.ts index c414bdc0b..e219874a7 100644 --- a/packages/shared.test/src/mock-ontology/mockOntology.ts +++ b/packages/shared.test/src/mock-ontology/mockOntology.ts @@ -257,6 +257,30 @@ export const MockOntology = { }, }, }, + queryWithOnlyOptionalArgs: { + apiName: "queryWithOnlyOptionalArgs", + description: "a query that only has optional args", + version: "version", + output: { type: "boolean" }, + parameters: { + string: { + type: "string", + nullable: true, + }, + }, + }, + queryWithOnlyRequiredArgs: { + apiName: "queryWithOnlyRequiredArgs", + description: "a query that only has required args", + version: "version", + output: { type: "boolean" }, + parameters: { + string: { + type: "string", + nullable: false, + }, + }, + }, }, } satisfies OntologyDefinition< | "Task"