slackapi / deno-slack-sdk

SDK for building Run on Slack apps using Deno

Home Page:https://api.slack.com/automation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Issue With Custom Types

anthonygualandri opened this issue · comments

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.

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

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

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[]>>'.

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 } };
  },
);

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

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 } };
  },
);

@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.