seratch / slack-edge

Slack app development framework for edge functions with streamlined TypeScript support
https://github.com/seratch/slack-edge-app-template
MIT License
87 stars 5 forks source link

[Deno] Potential type issue with SlackApp's SlackEdgeAppEnv #23

Closed gadfly361 closed 4 months ago

gadfly361 commented 4 months ago

First, thank you so much for this library! I am trying to test this out using Deno and got an unexpected linting error from a README example.

The snippet below is from the README for Deno.

import { SlackApp } from "https://deno.land/x/slack_edge@0.10.8/mod.ts";

const app = new SlackApp({
  env: {
    SLACK_SIGNING_SECRET: Deno.env.get("SLACK_SIGNING_SECRET"),
    SLACK_BOT_TOKEN: Deno.env.get("SLACK_BOT_TOKEN"),
    SLACK_LOGGING_LEVEL: "DEBUG",
  },
});

I am seeing a linter issue with a squiggly line under env that seems to be complaining about types. The message is as follows:

Type '{ SLACK_SIGNING_SECRET: string | undefined; SLACK_BOT_TOKEN: string | undefined; SLACK_LOGGING_LEVEL: "DEBUG"; }' is not assignable to type 'SlackEdgeAppEnv | SlackSocketModeAppEnv'.
  Type '{ SLACK_SIGNING_SECRET: string | undefined; SLACK_BOT_TOKEN: string | undefined; SLACK_LOGGING_LEVEL: "DEBUG"; }' is not assignable to type 'SlackSocketModeAppEnv'.
    Property 'SLACK_APP_TOKEN' is missing in type '{ SLACK_SIGNING_SECRET: string | undefined; SLACK_BOT_TOKEN: string | undefined; SLACK_LOGGING_LEVEL: "DEBUG"; }' but required in type '{ SLACK_SIGNING_SECRET?: string | undefined; SLACK_BOT_TOKEN?: string | undefined; SLACK_APP_TOKEN: string; }'.

The env appears to take in SlackAppOptions and it can take in SlackEdgeAppEnv or SlackSocketModeAppEnv.

export interface SlackAppOptions<
  E extends SlackEdgeAppEnv | SlackSocketModeAppEnv,
> {

I think the README example is trying to make use of SlackEdgeAppEnv, so looking at that I see:

export type SlackAppEnv = SlackLoggingLevel & {
  SLACK_SIGNING_SECRET?: string;
  SLACK_BOT_TOKEN?: string;
  SLACK_APP_TOKEN?: string;
};

export type SlackEdgeAppEnv = SlackAppEnv & {
  SLACK_SIGNING_SECRET: string;
  SLACK_BOT_TOKEN?: string;
};

Should SlackAppEnv (that SlackEdgeAppEnv depends on) include the SLACK_APP_TOKEN? If so, does the README example need to be updated?


image

seratch commented 4 months ago

Hi @gadfly361, thanks for sharing this.

Since the current code compiles and can work without any issues, I call this a bug on the Deno VS Code plugin. That being said, this is frustrating for developers, so I will update the document section as below:

import { SlackApp, SlackEdgeAppEnv, SlackSocketModeAppEnv } from "https://deno.land/x/slack_edge@0.10.8/mod.ts";

const app = new SlackApp<SlackEdgeAppEnv>({
  env: {
    SLACK_SIGNING_SECRET: Deno.env.get("SLACK_SIGNING_SECRET")!,
    SLACK_BOT_TOKEN: Deno.env.get("SLACK_BOT_TOKEN"),
    SLACK_LOGGING_LEVEL: "DEBUG",
  },
});

const app2 = new SlackApp<SlackSocketModeAppEnv>({
  env: {
    SLACK_APP_TOKEN: Deno.env.get("SLACK_APP_TOKEN")!,
    SLACK_BOT_TOKEN: Deno.env.get("SLACK_BOT_TOKEN"),
    SLACK_LOGGING_LEVEL: "DEBUG",
  },
});

Thanks again for flagging this!

gadfly361 commented 4 months ago

@seratch That works, thank you so much for the quick reply! 🍻