slack-notify icon indicating copy to clipboard operation
slack-notify copied to clipboard

Could not find a declaration file for module 'slack-notify'.

Open rescuevessel opened this issue 2 years ago • 1 comments

Hello,

I'm having a heck of a time trying to troubleshoot this error that I'm getting that's preventing me from using slack-notify. This is what VS Code is suggesting:

Try npm i --save-dev @types/slack-notify if it exists or add a new declaration (.d.ts) file containing declare module 'slack-notify';ts(7016)

Nothing I've tried has resolved the issue.

Thanks.

rescuevessel avatar Mar 01 '22 22:03 rescuevessel

You can use meanwhile this in a index.d.ts file in the src of your project:

declare module 'slack-notify' {
  interface SlackNofifier {
    send(args: string | SendArgs): Promise<void>;
  }

  interface SlackNotify extends SlackNofifier {
    extend(args: string | SendArgs): SlackNofifier;
    success(args: string | SendArgs): SlackNofifier;
    bug(args: string | SendArgs): SlackNofifier;
    alert(args: string | SendArgs): SlackNofifier;
  }

  interface SendArgs {
    text: string;
    channel?: string;
    icno_url?: string;
    icon_emoji?: string;
    unfurl_links?: number;
    username?: string;
    attachments?: SendAttachment[];
    fields?: { [key: string]: string }[];
  }

  interface SendAttachment {
    fallback: string;
    fields?: SendAttachmentField[];
  }

  interface SendAttachmentField {
    title: string;
    value: string;
    short: boolean;
  }

  function SlackNotifyFactory(webhookUrl: string): SlackNotify;

  export default SlackNotifyFactory;
}

matiasf9 avatar May 16 '22 22:05 matiasf9

please merge. it's useful

rand0mC0d3r avatar Aug 05 '22 19:08 rand0mC0d3r

I've verified this is fixed in 2.0.3 in my projects locally using VS Code. Let me know if you see otherwise. Thank you to @matiasf9 for the help!

andrewchilds avatar Aug 07 '22 02:08 andrewchilds