Open jeff-wood-readyup opened 1 day ago
@jeff-wood-readyup what if you try to import it this way:
import * as swell from 'swell-js';
@awwit we should fix if true
@jeff-wood-readyup what if you try to import it this way:
import * as swell from 'swell-js';
This was actually one of the first things I tried and it does remove the typescript error but it stops my code from actually working.
It seems that this method is importing the namespace for the types instead of actually importing the library.
Doing a little poking around myself I added this to the end of the index.d.ts file and it seems to have solved my problem.
declare const swell: {
version: string;
init: typeof init;
account: typeof account;
attributes: typeof attributes;
card: typeof card;
cart: typeof cart;
categories: typeof categories;
content: typeof content;
currency: typeof currency;
locale: typeof locale;
payment: typeof payment;
products: typeof products;
settings: typeof settings;
subscriptions: typeof subscriptions;
invoices: typeof invoices;
session: typeof session;
functions: typeof functions;
utils: typeof utils;
auth: typeof init;
request: typeof request;
get: typeof get;
put: typeof put;
post: typeof post;
delete: typeof _delete;
};
export default swell;
I have forked the library for now, happy to submit a PR but I have only started using Swell recently so I am not sure if this code would work for all the functionality of the library.
PR with fix is here - https://github.com/swellstores/swell-js/pull/197
I am having an issue with Typescript, it is saying the swell-js library does not have a default export and so it is not able to pull in the type definitions correctly, resulting in it defaulting to an any type.
My package.json dependencies:
Any help resolving this would be greatly appreciated, my code itself works fine but the type errors are very annoying to deal with. Thanks!