happiness (^_^) (^_^) (^_^) (^_^) (^_^) (^_^) (^_^) (^_^) (^_^) (^_^) (^_^) (^_^) happiness

jest globalで変数定義してもTS2304のname not found エラーが出るときの対処方法(Google Apps Script x jestのヒントつき)

前提

2日に及び、4時間くらいで判明したこと

declareするといい(その場しのぎ感)

jest.config.js

module.exports = {
  globals: {
    SlackApp: {
      create: () => {
        return {
          getChannel: (a) => {
            return {
              postMessage: (a) => {
                return a;
              }
            }
          }
        }
      }
    },
  }
}


以下、サンプルコード

declare const SlackApp: any

class SlackBot {
  constructor() {
    this.accessToken = ""
    this.slackApp = SlackApp.create(this.accessToken)
  }
}

関係ない所感

slack API x Google Apps Script x clasp x jestで開発しているのだが、普通の人間はやめたほうが良い。

数名しか使わないようなアプリケーションならほんとにギリギリいいかなと思う。

ちまたにアイデアが有るがゆえに、雰囲気でもできてしまうことによる地獄の始まり。そんな体験が待っているかもしれない。