-
Notifications
You must be signed in to change notification settings - Fork 29
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
TypeScript support #45
Comments
Thanks @asia-jankowska00 for raising this issue. We're currently in the process of adding TS support. |
Hi! Any progress on this issue? |
Hey @alinjie 👋 , no updates at the moment. Keep an eye on our change log for any announcements. |
Hi! Anything new about this? |
Seconded, it's a real turn off when you're used to a fully typed workflow. |
news on this? :) |
It would be so much appreciated + looks like a big part of the job has already been done in the past: https://github.com/swellstores/nextjs-commerce/tree/master/framework/swell/types |
I have the same request, but have decided to work on my own implementation of There is a lot to be typed still, but everything we're using seems to be correct. You can check progress or even copy it to an internal |
Hi @gusfune, thanks for all the work done! Although I'm having some trouble trying to implement your solution, I've copied the same files to my typescript Next.js project but it seems it's not working, I have the error that appears in the picture below, do you imagine any solution? |
The typing implementation is not fully done @FelipeCabreraB, so some types are written as |
Oh, I forgot one thing, to use it inside a project you need to wrap the tipings with a declare module.
|
Thanks @gusfune! That worked for me! |
One last update @FelipeCabreraB - you can now install
|
Thanks @gusfune! Additionally, we're including type definitions to swell-js itself, as well as including the remaining type definitions (avoiding For those who have custom models and fields, we'll be providing a facility to fetch matching response type definitions - that's further down the road, though. |
Why choosing to union in a single type both camel cased and snake cased interfaces? This introduces a load of errors as typescript can't infer which field is from, requiring to redeclare them. |
Basically because when getting in the options |
I for one use |
Can you share a code snippet that's throwing errors so I can look at it? I have not faced the same problem, but we might find a solution. |
Ok, I had the same issue locally. The solution could be using the CamelCase types, this is how I am handling it until we find a better solution to identify the types. So that would make the code: export interface CartContextState {
current?: CartCamelCase | undefined;
count: number;
}
const [state, setState] = createStore<CartContextState>({ count: 0 });
const cart: CartCamelCase = await Swell.cart.get();
if (cart) {
setState({ current: cart, count: cart.itemQuantity });
} Not sure about SolidJS, but in React works like a charm. @markus-gx do you have any ideas on this? |
I don't think is solidjs per se, more the combination of strictest tsconfig / eslint. Here's mine tsconfig.json {
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"jsx": "preserve",
"jsxImportSource": "solid-js",
"types": ["vite/client"],
"noEmit": true,
"isolatedModules": true,
"strict": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"allowUnusedLabels": false,
"allowUnreachableCode": false,
"exactOptionalPropertyTypes": true,
"noFallthroughCasesInSwitch": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
"noPropertyAccessFromIndexSignature": true,
"noUncheckedIndexedAccess": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"importsNotUsedAsValues": "error",
"checkJs": true,
"baseUrl": "./",
"paths": {
"~/*": ["./src/*"]
},
}
} and .eslintrc.cjs module.exports = {
env: {
browser: true,
es2021: true
},
parser: '@typescript-eslint/parser',
plugins: ['solid'],
extends: ['eslint:recommended', 'plugin:solid/typescript'],
overrides: [],
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module'
},
rules: {}
}; |
What I meant is, if you cast the results to const res = await Swell.cart.update({
billing:
card: response.billing.
},
}) as CartCamelCase This would solve the issues. I also sent an example from your code that would probably fix the errors. |
I followed your hint and now works, but is ugly to override every single method. Hope to see a better implementation in the future. |
Glad that it worked! |
I can update here that Swell has released typescript support and it's mostly functional as of 3.19.3. |
I'm writing my application in TypeScript and would like to see TypeScript typing support.
The text was updated successfully, but these errors were encountered: