When trying to use the following template, but converted to TypeScript, I get a type error with the SDK that I don't understand.
Template:
https://github.com/slack-samples/bolt-js-assistant-template
When converting from app.js to app.ts and attempting to transpile, you get endless errors.
When attempting to troubleshot and understand the types provided, you met with very deeply nested chains of types which are difficult to understand.
I guess my questions is — is it even productive to use typescript with Bolt?
Is everyone just using JavaScript now?
What do you recommend?
Are the below specific issues a bug?
This old issue seems to still hold true:
#826
Additionally, having same types not exported doesn't help
See below for example errors.
@slack/bolt version
4.2.1
Your App and Receiver Configuration
see template
Node.js runtime version
v20.16.0
Steps to reproduce:
git clone https://github.com/slack-samples/bolt-js-assistant-template.git
cd bolt-js-assistant-template
npm install
npm i -D typescript ts-node
mv app.js app.ts
npx ts-node ./app.ts
Expected result:
Maybe my expectations are too high, but I didn't expect so many type issues to troubleshoot, for example the first one beats me (see below error).
The infered type of the prompts array looks satisfactory, but for whatever reason it doesn't work.
Here is the type:
|
interface SetSuggestedPromptsArguments { |
|
/** @description Prompt suggestions that appear when opening assistant thread. */ |
|
prompts: [AssistantPrompt, ...AssistantPrompt[]]; |
|
/** @description Title for the prompts. */ |
|
title?: string; |
|
} |
|
|
|
interface AssistantPrompt { |
|
/** @description Title of the prompt. */ |
|
title: string; |
|
/** @description Message of the prompt. */ |
|
message: string; |
|
} |
I had to research as to why you use this type:
prompts: [AssistantPrompt, ...AssistantPrompt[]];
It's a "non-empty array" type, which may be more trouble than it's worth?
(How can you even check the array size at compile time?)
Interestingly if I make this change to the interface, the typescript is happy
prompts: AssistantPrompt[];
Or if you could export the type, then I could import them type and force it like so:
const prompts: [AssistantPrompt, ...AssistantPrompt[]] = [
...
Actual result:
Many errors including:
app.ts:82:35 - error TS2322: Type '{ title: string; message: string; }[]' is not assignable to type '[AssistantPrompt, ...AssistantPrompt[]]'.
Source provides no match for required element at position 0 in target.
82 await setSuggestedPrompts({ prompts, title: 'Here are some suggested options:' });
~~~~~~~
node_modules/@slack/bolt/dist/Assistant.d.ts:30:5
30 prompts: [AssistantPrompt, ...AssistantPrompt[]];
~~~~~~~
The expected type comes from property 'prompts' which is declared here on type 'SetSuggestedPromptsArguments'
sorry for the rant — but it remains really challenging to use Typescript with Slack 😞
When trying to use the following template, but converted to TypeScript, I get a type error with the SDK that I don't understand.
Template:
https://github.com/slack-samples/bolt-js-assistant-template
When converting from app.js to app.ts and attempting to transpile, you get endless errors.
When attempting to troubleshot and understand the types provided, you met with very deeply nested chains of types which are difficult to understand.
I guess my questions is — is it even productive to use typescript with Bolt?
Is everyone just using JavaScript now?
What do you recommend?
Are the below specific issues a bug?
This old issue seems to still hold true:
#826
Additionally, having same types not exported doesn't help
See below for example errors.
@slack/boltversion4.2.1
Your
Appand Receiver Configurationsee template
Node.js runtime version
v20.16.0
Steps to reproduce:
git clone https://github.com/slack-samples/bolt-js-assistant-template.git cd bolt-js-assistant-template npm install npm i -D typescript ts-node mv app.js app.ts npx ts-node ./app.tsExpected result:
Maybe my expectations are too high, but I didn't expect so many type issues to troubleshoot, for example the first one beats me (see below error).
The infered type of the
promptsarray looks satisfactory, but for whatever reason it doesn't work.Here is the type:
bolt-js/src/Assistant.ts
Lines 47 to 59 in e6f3f1c
I had to research as to why you use this type:
It's a "non-empty array" type, which may be more trouble than it's worth?
(How can you even check the array size at compile time?)
Interestingly if I make this change to the interface, the typescript is happy
Or if you could export the type, then I could import them type and force it like so:
Actual result:
Many errors including:
sorry for the rant — but it remains really challenging to use Typescript with Slack 😞