keenethics/svelte-notifications

Typescript error

Closed this issue · 6 comments

Describe the bug
When using typescript, addNotification() definition does not take argument. so on VSCode, it shows errors.

To Reproduce

<script lang="ts">
  import { getNotificationsContext } from 'svelte-notifications'
  const { addNotification } = getNotificationsContext()

  // VScode shows errors: Expected 0 arguments, but got 1.ts(2554)
  addNotification({
          text: 'TestCase created',
          type: 'success',
          position: 'top-right',
          removeAfter: 2000
        })

Expected behavior
Should be no error

Screenshots

Screen Shot 2021-07-13 at 11 05 55 AM
Screen Shot 2021-07-13 at 11 06 03 AM

Another problem is that when using <Notifications> in .svelte file, it is highlighted as error: JSX element type Notifications does not have any construct or call signatures .

I modified the types.d.ts like this to fix both errors:

export default class Notifications extends SvelteComponent {
    $$prop_def: NotificationsProps;
}

export function getNotificationsContext(): {
    subscribe: any;
    addNotification: addNotification;
    removeNotification: removeNotification;
    clearNotifications: clearNotifications;
};

Do you need a pull request?

pull request: #49

I also have this JSX element error! Would be happy if the fix would be merged!

Seems it is already merged. Did you test to see if it fix your JSX error?

Ah right, and yes, the problem is solved! But it's not updated on npmjs.com. Would be great if a new version is released so I don't have to install from Github master branch!

@apirogov @shaozi I released a new version. If everything was fixed, please let me know so that I can close the issue