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

improved type resolution for action method #349

Merged
merged 5 commits into from
Dec 19, 2019

Conversation

stevengill
Copy link
Member

Summary

Related to #326 and #325.

A small improvement based on comments by @aoberoi at #326 (comment).

Now the action argument gets narrowed down to appropriate action based on type. Example:

app1.action({ type: 'block_actions' }, ({ action }) => {
// action is now BlockAction instead of SlackAction
});

Currently, no support for the other two use cases @aoberoi pointed out:

  1. Typescript should complain about a type:message_action also passing an action_id (action_id is specific to BlockActions)
  2. Helping a developer understand what the options might be for the type constraint by allowing your editor's inference to give you suggestions.

Still need to add tests for these changes.

Let me know your thoughts!

Requirements (place an x in each [ ])

@stevengill stevengill self-assigned this Dec 18, 2019
@stevengill stevengill added the enhancement M-T: A feature request for new functionality label Dec 18, 2019
@codecov
Copy link

codecov bot commented Dec 18, 2019

Codecov Report

Merging #349 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #349   +/-   ##
=====================================
  Coverage      73%    73%           
=====================================
  Files           7      7           
  Lines         500    500           
  Branches      146    146           
=====================================
  Hits          365    365           
  Misses        103    103           
  Partials       32     32
Impacted Files Coverage Δ
src/App.ts 78.23% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d59319c...8bb6838. Read the comment docs.

@seratch
Copy link
Member

seratch commented Dec 18, 2019

I verified how it works on Visual Studio Code and understood this is greatly beneficial. I like this idea very much 👍

block_actions

message_action

@stevengill
Copy link
Member Author

Thanks @seratch for the great review and including screenshots!

I added dtslint tests to this PR with 5ae4ba5.

I followed the pattern from node-slack-sdk to make the integration tests their own package unaware of local files to simulate a real world experience.

Integration tests will test the latest released version of bolt. The issue here is that the released version of bolt doesn't include the changes from this PR to test. So I ended up doing a npm link in my local @slack/bolt repo and then ran npm link @slack/bolt in my integration tests folder. This allowed me to run these tests against my local bolt.

I'll leave a few comments in line myself that hopefully @aoberoi can answer.

@stevengill
Copy link
Member Author

One other thing I forgot to mention, I haven't tied this into the global npm test yet (so no travisCI integration). Definitely will want to do that, but maybe after the next bolt release so our CI doesn't go red.

@aoberoi
Copy link
Contributor

aoberoi commented Dec 18, 2019

Integration tests will test the latest released version of bolt. The issue here is that the released version of bolt doesn't include the changes from this PR to test. So I ended up doing a npm link in my local @slack/bolt repo and then ran npm link @slack/bolt in my integration tests folder. This allowed me to run these tests against my local bolt.

@stevengill is this something we can automate in the scripts that run on CI? it drastically reduces the usefulness of these tests in CI if they test against the latest release as opposed to the changes being made in the branch/PR.

Maybe we can use a local pathin the package.json entry for @slack/bolt instead of a version number? i haven't tried this in a while, so i'm not sure if there are any downsides to it.

Copy link
Contributor

@aoberoi aoberoi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple small nits, but overall looks great!

integration-tests/package.json Outdated Show resolved Hide resolved
integration-tests/package.json Outdated Show resolved Hide resolved
integration-tests/types/action.ts Show resolved Hide resolved
// Should error because message_action doesn't have type action_id
// $ Expect Error
app.action({ type: 'message_action', action_id: 'dafasf' }, ({ action }) => {
// NOT WORKING
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once this PR lands, can we open an issue to investigate how we might get this test (and the last one in this file) to pass? I have an idea that might work, but its not worth blocking this PR over.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, i tried out the idea for a couple mins and couldn't get it to work. doesn't mean its not possible, but would likely take more time than i have today to fully investigate.

"type": "node",
"request": "launch",
"name": "Integration Type Checker",
"program": "${workspaceFolder}/node_modules/dtslint/bin/index.js",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be the npm test script instead of directly trying to run dtslint?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that by following https://code.visualstudio.com/docs/nodejs/nodejs-debugging, but it seems very specific to the debug command. I've tried swapping it for npm test, but it just hangs.

        {
            "type": "node",
            "request": "launch",
            "name": "npm test",
            "cwd": "${workspaceFolder}",
            "runtimeExecutable": "npm",
            "runtimeArgs": [
                "run-script", "test"
            ],
            "port": 9229
        },

@stevengill
Copy link
Member Author

I've pushed changes based on the feedback.

I've updated the bolt dependency to use the local bolt instead of the released one. Seems to be working fine.

I'll do one more update so the global npm test will run these integration tests too.

@stevengill stevengill merged commit 1655999 into slackapi:master Dec 19, 2019
@seratch seratch mentioned this pull request Mar 18, 2020
9 tasks
@stevengill stevengill deleted the Issue325 branch May 22, 2020 19:04
@seratch seratch mentioned this pull request Jun 3, 2020
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement M-T: A feature request for new functionality semver:patch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants