-
Notifications
You must be signed in to change notification settings - Fork 81
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 #61
Comments
@ampirzadeh A PR with the types would be more than welcome! |
You can add typescript support manually,
|
Tried @austinbakker solution, but I keep getting the |
@ luxial did you try restarting you editor (mind need to wait a minute for everything to load) || Have you added the plugin to the nuxt.config.js file? And what does your tsconfig.json looklike. |
Hi @austinbakker , yesterday I made a quick tryout and notice that I was using Another thing missing was the login(params?:object) : Promise<any>; Login works great when added that. Right now, I'm only getting this error (
Any idea about this error? If someone needs the plugin file with the // ~/plugins/strapi.ts
// not used directly but needed for typescript support
import { Plugin } from '@nuxt/types'
interface Strapi {
login(params?:object) : Promise<any>;
find(collection:string, params?:object) : Promise<any>;
findone(collection:string, id:number) : Promise<any>;
create(collection:string, data:object) : Promise<any>;
count(collection:string, params?:object) : Promise<any>;
update(collection:string, id:number, data:object) : Promise<any>;
delete(collection:string, id:number) : Promise<any>;
}
declare module 'vue/types/vue' {
// this.$myInjectedFunction inside Vue components
interface Vue {
$strapi: Strapi
}
}
declare module '@nuxt/types' {
// nuxtContext.app.$myInjectedFunction inside asyncData, fetch, plugins, middleware, nuxtServerInit
interface NuxtAppOptions {
$strapi: Strapi
}
// nuxtContext.$myInjectedFunction
interface Context {
$strapi: Strapi
}
}
declare module 'vuex/types/index' {
// this.$myInjectedFunction inside Vuex stores
interface Store<S> {
$strapi: Strapi
}
} |
What is Expected: No Error
What is happening
I wanted to use this module with nuxt, typescript and vue composition api but there are no type declarations for it, so I started writing my own, But still there is an error telling me that there is no $strapi on context when I want to use $strapi in a middleware.
The exact error:
{
"resource": "/project/middleware/auth.ts",
"owner": "typescript",
"code": "2339",
"severity": 8,
"message": "Property '$strapi' does not exist on type 'Context'.",
"source": "ts",
"startLineNumber": 4,
"startColumn": 29,
"endLineNumber": 4,
"endColumn": 36
}
I want to be able to use this module in a nuxt-typescript project without errors.
What I think would fix the error
I think rewriting the module in typescript or just providing @types folder would fix the issue.
I myself would be interested in helping.
My code
The text was updated successfully, but these errors were encountered: