Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue With Custom Types #279

Open
anthonygualandri opened this issue Feb 21, 2024 · 8 comments
Open

Issue With Custom Types #279

anthonygualandri opened this issue Feb 21, 2024 · 8 comments

Comments

@anthonygualandri
Copy link

Question

I’m getting the following typescript error when trying to implement the suggested structure for a custom object type within a custom array found here and here. I’m not exactly sure how to resolve this. Any help is greatly appreciated!

Type '{}' is missing the following properties from type 'CustomType<TypedObjectProperties, TypedObjectRequiredProperties, { name: string; type: "array"; items: { ...; }; }>': id, title, description, definition, and 4 more.

Context

Environment

"deno-slack-sdk/": "https://deno.land/x/deno_slack_sdk@2.5.0/",
"deno-slack-api/": "https://deno.land/x/deno_slack_api@2.1.2/",

deno 1.37.0 (release, x86_64-unknown-linux-gnu)
v8 11.8.172.3
typescript 5.2.2

Requirements

Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.

@srajiang
Copy link
Member

@anthonygualandri - Can you share a snippet of the type you have defined, so that we can try to reproduce the error?

@anthonygualandri
Copy link
Author

anthonygualandri commented Feb 21, 2024

@anthonygualandri
Copy link
Author

@srajiang any update on what might be going on here with this?

@anthonygualandri
Copy link
Author

Still struggling to understand why I'm getting this error when using Slack custom types in the function output parameters:

Argument of type '({ inputs, client, env }: FunctionContext<FunctionRuntimeParameters<{}, never[]>>) => Promise<{ outputs: { schedules_records: { slack_id: string; staff_id: string; ... 4 more ...; end_time_unix: number; }[]; }; error?: undefined; } | { ...; } | undefined>' is not assignable to parameter of type 'BaseEnrichedSlackFunctionHandler<FunctionRuntimeParameters<{}, never[]>, FunctionRuntimeParameters<{ schedules_records: { type: CustomType<TypedObjectProperties, TypedObjectRequiredProperties<TypedObjectProperties>, { ...; }>; items: { ...; }; description: string; }; }, never[]>>'. Type '({ inputs, client, env }: FunctionContext<FunctionRuntimeParameters<{}, never[]>>) => Promise<{ outputs: { schedules_records: { slack_id: string; staff_id: string; ... 4 more ...; end_time_unix: number; }[]; }; error?: undefined; } | { ...; } | undefined>' is not assignable to type 'AsyncFunctionHandler<FunctionRuntimeParameters<{}, never[]>, FunctionRuntimeParameters<{ schedules_records: { type: CustomType<TypedObjectProperties, TypedObjectRequiredProperties<TypedObjectProperties>, { ...; }>; items: { ...; }; description: string; }; }, never[]>, FunctionContext<...>>'. Type 'Promise<{ outputs: { schedules_records: { slack_id: string; staff_id: string; start_time: string; end_time: string; time_zone: string; start_time_unix: number; end_time_unix: number; }[]; }; error?: undefined; } | { ...; } | undefined>' is not assignable to type 'Promise<FunctionHandlerReturnArgs<FunctionRuntimeParameters<{ schedules_records: { type: CustomType<TypedObjectProperties, TypedObjectRequiredProperties<TypedObjectProperties>, { ...; }>; items: { ...; }; description: string; }; }, never[]>>>'. Type '{ outputs: { schedules_records: { slack_id: string; staff_id: string; start_time: string; end_time: string; time_zone: string; start_time_unix: number; end_time_unix: number; }[]; }; error?: undefined; } | { ...; } | undefined' is not assignable to type 'FunctionHandlerReturnArgs<FunctionRuntimeParameters<{ schedules_records: { type: CustomType<TypedObjectProperties, TypedObjectRequiredProperties<TypedObjectProperties>, { ...; }>; items: { ...; }; description: string; }; }, never[]>>'. Type 'undefined' is not assignable to type 'FunctionHandlerReturnArgs<FunctionRuntimeParameters<{ schedules_records: { type: CustomType<TypedObjectProperties, TypedObjectRequiredProperties<TypedObjectProperties>, { ...; }>; items: { ...; }; description: string; }; }, never[]>>'.

@seratch
Copy link
Member

seratch commented Feb 26, 2024

Hi @anthonygualandri, when you use the custom type this way, the compilation error should be resolved. If you want to use the type for an array, you can follow the document example.

import { DefineFunction, SlackFunction } from "deno-slack-sdk/mod.ts";
import { PaystubsRecordType } from "../foo.ts";

export const SampleFunctionDefinition = DefineFunction({
  callback_id: "sample_function",
  title: "Sample function",
  description: "A sample function",
  source_file: "functions/sample_function.ts",
  input_parameters: {
    properties: {
      something: { type: PaystubsRecordType },
    },
    required: ["something"],
  },
  output_parameters: {
    properties: {
      something: { type: PaystubsRecordType },
    },
    required: ["something"],
  },
});

export default SlackFunction(
  SampleFunctionDefinition,
  async () => {
    const something = { flexibleObject: {} };
    return { outputs: { something } };
  },
);

@anthonygualandri
Copy link
Author

anthonygualandri commented Feb 26, 2024

Thanks @seratch for the response. Unfortunately, I'm not seeing this resolve the issue. Here's my function definition where I'm using the custom type. Maybe that will help reveal what it is that I'm doing wrong.

image

image

@seratch
Copy link
Member

seratch commented Feb 26, 2024

It seems that your types are not compatible with the expected array with the generics. You can start with a simpler code snippet like below and modify it step by step:

import { DefineFunction, Schema, SlackFunction } from "deno-slack-sdk/mod.ts";
import { PaystubsRecordType } from "../foo.ts";

export const SampleFunctionDefinition = DefineFunction({
  callback_id: "sample_function",
  title: "Sample function",
  description: "A sample function",
  source_file: "functions/sample_function.ts",
  input_parameters: { properties: {}, required: [] },
  output_parameters: {
    properties: {
      something: {
        type: Schema.types.array,
        items: { type: PaystubsRecordType },
      },
    },
    required: ["something"],
  },
});

export default SlackFunction(
  SampleFunctionDefinition,
  async () => {
    const something = [{ flexibleObject: {} }];
    return { outputs: { something } };
  },
);

@anthonygualandri
Copy link
Author

anthonygualandri commented Feb 26, 2024

@seratch Finally got it to work. So my types and all were fine. It needed to be this for the return value:

return { outputs: { outputparameter_property: [{customtype_property: value}] } };

So in the example you gave above it would need to be:

return { outputs: { something: something } }; not just return { outputs: { something } };

Thanks for the help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants