I'm working hard to introduce typescript to Nuxt.js with Option API.
In Current Code, we use middleware, asyncData and fetch methods.
After I switched lang to ts (<script lang="ts">), typescript says error for the above methods.
like this (about middleware)
Object literal may only specify known properties, and 'middleware' does not exist in type 'ComponentOptions<Vue, DefaultData<Vue>, DefaultMethods<Vue>, DefaultComputed, PropsDefinition<DefaultProps>, DefaultProps>'.
Then, I googled this problem and found this solution, but it does not work maybe because this solution is about Nuxt with Class API...
summary of my .vue file:
<script lang="ts">
import Vue from 'vue'
export default Vue.extend({
async middleware({store, params, from}) {
// Error is occuring here...
// Object literal may only specify known properties, and 'middleware' does not exist in type 'ComponentOptions<Vue, DefaultData<Vue>, DefaultMethods<Vue>, DefaultComputed, PropsDefinition<DefaultProps>, DefaultProps>'.
},
asyncData({params}) {
~~~
},
});
</script>
tsconfig.json:
{
"compilerOptions": {
"target": "ES2018",
"module": "ESNext",
"moduleResolution": "Node",
"lib": [
"ESNext",
"ESNext.AsyncIterable",
"DOM"
],
"esModuleInterop": true,
"allowJs": true,
"sourceMap": true,
"strict": true,
"noEmit": true,
"baseUrl": ".",
"paths": {
"~/*": [
"./*"
],
"@/*": [
"./*"
]
},
"types": [
"@types/node",
"@nuxt/types"
]
},
"exclude": [
"node_modules"
]
}
Is there any way to use those methods in Nuxt with Option API ?