nuxt-community / nuxt-property-decorator

Property decorators for Nuxt (base on vue-property-decorator)
https://github.com/kaorun343/vue-property-decorator
MIT License
399 stars 34 forks source link

after upgrade nuxt to 2.5.1, shows ts warning for Component decorator #37

Closed TonyLuo closed 4 years ago

TonyLuo commented 5 years ago

after upgrade nuxt to 2.5.1, VSCode editor shows ts warning for Component decorator:

(property) ComponentOptions<Vue, DefaultData<Vue>, DefaultMethods<Vue>, DefaultComputed, PropsDefinition<Record<string, any>>, Record<string, any>>.components?: {
    [key: string]: VueConstructor<Vue> | FunctionalComponentOptions<any, PropsDefinition<any>> | ComponentOptions<never, any, any, any, any, Record<string, any>> | AsyncComponentPromise<any, any, any, any> | AsyncComponentFactory<...>;
} | undefined

Argument of type '{ components: { Card: Vue; }; }' is not assignable to parameter of type 'VueClass<Vue>'.
  Object literal may only specify known properties, but 'components' does not exist in type 'VueClass<Vue>'. Did you mean to write 'component'?ts(2345)
@Component({
    components: {
        Card
    }
})
export default class extends Vue {
}

package.json:

{
    "name": "weixin-nuxt",
    "description": "企业微信页面",
    "version": "2.4.5",
    "private": true,
    "dependencies": {
        "@nuxtjs/axios": "5.4.1",
        "js-cookie": "^2.2.0",
        "nuxt": "^2.5.1",
        "nuxt-property-decorator": "^2.1.3",
        "vant": "^1.6.11",
        "vuex-class": "0.3.2",
        "weixin-js-sdk": "^1.4.0-test"
    },
    "scripts": {
        "dev": "nuxt",
        "build": "nuxt build",
        "start": "nuxt start",
        "generate": "nuxt generate",
        "post-update": "yarn upgrade --latest"
    },
    "devDependencies": {
        "@nuxt/typescript": "^2.5.1",
        "@nuxtjs/style-resources": "^0.1.2",
        "@types/node": "10.14.1",
        "@types/webpack-env": "1.13.9",
        "less": "^3.9.0",
        "less-loader": "^4.1.0"
    }
}

tsconfig.json:

{
    "compilerOptions": {
        "target": "esnext",
        "module": "esnext",
        "moduleResolution": "node",
        "lib": [
            "esnext",
            "esnext.asynciterable",
            "dom"
        ],
        "esModuleInterop": true,
        "experimentalDecorators": true,
        "allowSyntheticDefaultImports": true,
        "allowJs": true,
        "sourceMap": true,
        "strict": true,
        "noImplicitAny": false,
        "noEmit": true,
        "baseUrl": "./",
        "skipLibCheck": true,
        "importHelpers": true,
        "paths": {
            "*": [
                "types/*"
            ],
            "~/*": [
                "./*"
            ],
            "@/*": [
                "./*"
            ]
        },
        "types": [
            "@types/node",
            "@types/webpack-env"
        ]
    },
    "exclude": [
        "node_modules"
    ]
}
husayt commented 5 years ago

@TonyLuo do you still have this issue with nuxt 2.6.0? If yes could you provide a reproducible simple project on codesandbox.

TonyLuo commented 5 years ago

still the same issue after upgrade to nuxt 2.6.1. I fix it by adding "@nuxt/vue-app" into tsconfig.json

tsconfig.json

{
    "compilerOptions": {
        "target": "esnext",
        "module": "esnext",
        "moduleResolution": "node",
        "lib": [
            "esnext",
            "esnext.asynciterable",
            "dom"
        ],
        "esModuleInterop": true,
        "experimentalDecorators": true,
        "allowSyntheticDefaultImports": true,
        "suppressImplicitAnyIndexErrors": true,
        "allowJs": true,
        "sourceMap": true,
        "strict": true,
        "noImplicitAny": false,
        "noEmit": true,
        "baseUrl": "./",
        "skipLibCheck": true,
        "importHelpers": true,
        "paths": {
            "*": [
                "types/*"
            ],
            "~/*": [
                "./*"
            ],
            "@/*": [
                "./*"
            ]
        },
        "types": [
            "@nuxt/vue-app",
            "@types/node",
            "@types/webpack-env"
        ]
    },
    "exclude": [
        "node_modules"
    ]
}
TonyLuo commented 5 years ago

oh... so bad. Adding "@nuxt/vue-app" into tsconfig.json can fix this issue in nuxt 2.5.1 , but it doesn't work in nuxt 2.6.1.... image image

husayt commented 5 years ago

This is my config and all works ok with 2.6.1. If you still have a problem best is share a simple project with your issue.

{
  "compilerOptions": {
    "outDir": "./dist.js",
    "resolveJsonModule": true,
    "allowJs": true,
    "checkJs": true,
    "allowSyntheticDefaultImports": true,
    "suppressImplicitAnyIndexErrors": true,
    "esModuleInterop": true,
    "jsx": "preserve",
    "experimentalDecorators": true,
    "sourceMap": true,
    "strict": true,
    "noImplicitAny": false,
    "noUnusedLocals": true,
    "noUnusedParameters": false,
    "removeComments": true,
    "pretty": true,
    "baseUrl": ".",
    "paths": {
      "~/*": [
        "src/*"
      ],
      "@/*": [
        "src/*"
      ]
    },
    "plugins": [
      {
        "name": "typescript-tslint-plugin"
      }
    ],
    "types": [
      "@types/node",
      "@types/jest",
      "@nuxt/vue-app-edge"
    ],
    "target": "esnext",
    "module": "esnext",
    "moduleResolution": "node",
    "lib": [
      "esnext",
      "esnext.asynciterable",
      "dom"
    ],
    "noEmit": true
  },
  "include": [
    "./index.d.ts",
    "./rest.d.ts",
    "./src/**/*.ts",
    "./src/**/*.vue"
  ],
  "exclude": [
    ".nuxt",
    ".vscode",
    "dist",
    "dist.js",
    "node_modules"
  ]
} 
rubybrowncoat commented 5 years ago

This issue is back with a vengeance with nuxt 2.9 and 2.9.1.

husayt commented 5 years ago

What's your latest config? I use it with all versions of nuxt without those problems.

On Fri, 23 Aug 2019, 14:10 rubybrowncoat, notifications@github.com wrote:

This issue is back with a vengeance with nuxt 2.9 and 2.9.1.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/nuxt-community/nuxt-property-decorator/issues/37?email_source=notifications&email_token=AAI5PLGJD6F4EKDIQ4DHNSDQF7HSVA5CNFSM4HBP3HK2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5AA3PY#issuecomment-524291519, or mute the thread https://github.com/notifications/unsubscribe-auth/AAI5PLCAN6746JISWTMAW43QF7HSVANCNFSM4HBP3HKQ .

JakubKoralewski commented 4 years ago

@husayt I think the problem still exists or there is a problem on my side, I've got more info in #62