-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
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
Vuejs type inference does not work with TS 3.4.x #9873
Comments
Seems to belong into the vetur repository then, right? |
No, because the errors also appear in the terminal when using patrick@patrick-Ubuntu:~/dev/test/test$ yarn serve
yarn run v1.15.2
$ vue-cli-service serve
INFO Starting development server...
Starting type checking service...
Using 1 worker with 2048MB memory limit
98% after emitting CopyPlugin
DONE Compiled successfully in 2925ms 09:12:39
Type checking in progress...
App running at:
- Local: http://localhost:8081/
- Network: http://10.25.1.148:8081/
Note that the development build is not optimized.
To create a production build, run yarn build.
ERROR in /home/patrick/dev/test/test/src/components/HelloWorld.vue
104:19 Property 'test' does not exist on type 'CombinedVueInstance<Vue, {}, {}, {}, Readonly<{ msg: string; }>>'.
102 | computed: {
103 | testComp: function() {
> 104 | return this.test === false;
| ^
105 | }
106 | }
107 | });
Version: typescript 3.4.3
Time: 3161ms |
Looks like TS3.4 has multiple inference issue... The minimal repro: Vue.component('test', {
data() {
return {
test: 123
}
},
computed: {
ttt() {
return this.test + 1
}
},
}) Also spotted another failure: The catch-all type signature of component component(id: string, definition?: ComponentOptions<V>): ExtendedVue<V, {}, {}, {}, {}>; is causing union type to fail checking. I need more time for investigation... |
I wonder if properties in |
Of course... |
I filed the same bug against Typescript (microsoft/TypeScript#30854) |
Minimal repro: type TypedDef<Data, Computed> =
ComponentOptions<Data, Computed> &
ThisType<Data & Computed>
type DataDef<Data> = () => Data
export interface ComponentOptions<Data, Computed> {
data?: DataDef<Data>
computed?: Accessors<Computed>
}
export type Accessors<T> = {
[K in keyof T]: () => T[K]
}
declare function component<Data, Computed>(def: TypedDef<Data, Computed>): void;
component({
data() {
return {
foo: 23
}
},
computed: {
bar() {
// return this.foo + 1 // comment out the return solves the problem
}
}
}) The problem seems to be cyclic inference issue. If the computed property doesn't reference data, the compiler error goes away. I think it should goes to TypeScript's repo. |
One workaround is assigning a return type to computed type TypedDef<Data, Computed> =
ComponentOptions<Data, Computed> &
ThisType<Data & Computed>
type DataDef<Data> = () => Data
export interface ComponentOptions<Data, Computed> {
data?: DataDef<Data>
computed?: Accessors<Computed>
}
export type Accessors<T> = {
[K in keyof T]: () => T[K]
}
declare function component<Data, Computed>(def: TypedDef<Data, Computed>): void;
component({
data() {
return {
foo: 23
}
},
computed: {
bar(): number { // adding the return type, seems to solve the error
return this.foo + 1
}
}
}) |
Good call. Just discovered that workaround is documented here. |
The best way to avoid the issue now is to annotate return type of computed method... We cannot make much progress since it is an upstream issue in TS. |
Unfortunately it also happens if you have a validator on a prop, and it isn't fixed with the annotation workaround: export default Vue.extend({
props: {
foobar: {
required: true,
type: String,
validator(foobar: string): boolean { return ['foo', 'bar'].includes(foobar); },
},
},
data(): { initialFoobar: string } {
return {
initialFoobar: this.foobar, //=> Property 'foobar' does not exist on type 'CombinedVueInstance<Vue, {}, {}, {}, Readonly<{}>>'
};
},
computed: {
foobang(): string {
return `${this.foobar}!`; //=> Property 'foobar' does not exist on type 'CombinedVueInstance<Vue, {}, {}, {}, Readonly<{}>>'
},
},
}); Breaks our entire build, easily 100+ errors after stepping up from TS v3.3.3333 to v3.4.4. Too bad, too, because this version of TS introduced some handy features for exactly what I'm working on right now... 😩 |
Also happens if you have a export default Vue.extend({
props: {
foobar: {
required: true,
type: String,
},
// With this, errors. Without this, no errors.
someFunc: {
required: true,
type: Function,
},
},
data(): { initialFoobar: string } {
return {
initialFoobar: this.foobar, //=> Property 'foobar' does not exist on type 'CombinedVueInstance<Vue, {}, {}, {}, Readonly<{}>>'
};
},
computed: {
foobang(): string {
return `${this.foobar}!`; //=> Property 'foobar' does not exist on type 'CombinedVueInstance<Vue, {}, {}, {}, Readonly<{}>>'
},
},
}); |
(Note: the two examples I gave are not fixed by the workaround mentioned) |
@kjleitz not sure what's the issue, it seems to work on my vscode: I would recommend annotation the function with PropType export default Vue.extend({
props: {
foobar: {
required: true,
type: String,
},
someFunc: {
required: true,
type: Function as PropType<()=>any>, // try annotate with a type
},
},
data(): { initialFoobar: string } {
return {
initialFoobar: this.foobar, //=> Property 'foobar' does not exist on type 'CombinedVueInstance<Vue, {}, {}, {}, Readonly<{}>>'
};
},
computed: {
foobang(): string {
return `${this.foobar}!`; //=> Property 'foobar' does not exist on type 'CombinedVueInstance<Vue, {}, {}, {}, Readonly<{}>>'
},
},
}); What typescript and vuejs versions are you using? |
Please refer to the comment here: |
did this//`/types/myVue.d.ts`
import Vue from "vue";
declare module "vue/types/vue" {
interface Vue {
$myConfig: string;
}
} got this
|
We also had a component start throwing a lot of errors after upgrading from TS Thanks to this comment, went back and checked that component and, sure enough, one of the computed properties did not have a return type annotated. With that annotation added, the build compiled without issue. Per the TS comment, perhaps the docs would be best updated as |
Yeah, unfortunately it sounds like this was just the same limitation we've always known. My best advice is to make an ESLint rule that catches this, since it is hard to report circularities for us during inference. |
To add to @kjleitz unresolved issues, a prop type of |
I found a very similar issue, with the exact same error, if I used a render() method that used some "props" and wasn't annotated as returning VNode. Weirdly, instead of getting errors about the render method, or about "props", I got errors about some "data" I used in the mounted() and beforeDestroy() methods. |
Best workaround is to use the new Vue Composition API. It is a lot cleaner for typescript and works also with typescript versions > 3.3.4000. |
I just Wonder Any Workaround that can Work? |
when using composition api, I NEED TO access my custom props in setup function, and I always get type error saying "Property 'pagination' does not exist on type xxx", so this is never a workaround, i think. |
@AlanKnightly this has been working for me: import { createComponent } from '@vue/composition-api';
export default createComponent({
props: {
rows: Array,
page: Number,
filterKey: String
},
setup(props, context) {
const currentPage = props.page;
return {
currentPage
};
}
}); |
Closing as this cannot be fixed and is documented: https://vuejs.org/v2/guide/typescript.html#Annotating-Return-Types |
* package.json: add Nextcloud, Vue, typescipt dependencies (from Nextcloud) * remove .ts suffix from import paths (causes build error otherwise) * add declare global to define Nextcloud types. This should be changed to @nextcloud/typings. * annotated import of Nextcloud components (JS) with @ts-expect-error to solve tsc errors. This is most likely due to missing type definitions. Unclear how Nextcloud core made this working. * tsconfig: extend from @vue/tsconfig/tsconfig.json as documented elsewhere and as done in Nextcloud's core tsconfig.json Build fails with errors like ERROR in /app/src/components/AuthTokenSetup.vue.ts 47:9-14 [tsl] ERROR in /app/src/components/AuthTokenSetup.vue.ts(47,10) TS2339: Property 'reset' does not exist on type 'CreateComponentPublicInstance<{}, { authTokenStore: Store<"auth-token", { tokens: IToken[]; }, {}, { updateToken(token: IToken): Promise<any>; addToken(name: string): Promise<ITokenResponse | null>; deleteToken(token: IToken): Promise<...>; wipeToken(token: IToken): Promise<...>; renameToken(token: IToken, newName: ...'. This hints at Typescript not being able to infer types from the component definition. Related issues: * vuejs/vue#9873 * vuejs/vue#12628 * vuejs/vue#8721 Unsuccessfully attempted proposed solutions: * Declaring return types on methods like: reset(): void { async submit(): Promise<void> { * Using arrow functions Did not work and would introduce new errors anyway * Defining interfaces for the returned component Caused another rabbit hole of more and more required type definitions, that should be infered by the Vue typings anyway
* package.json: add Nextcloud, Vue, typescipt dependencies (from Nextcloud) * remove .ts suffix from import paths (causes build error otherwise) * add declare global to define Nextcloud types. This should be changed to @nextcloud/typings. * annotated import of Nextcloud components (JS) with @ts-expect-error to solve tsc errors. This is most likely due to missing type definitions. Unclear how Nextcloud core made this working. * tsconfig: extend from @vue/tsconfig/tsconfig.json as documented elsewhere and as done in Nextcloud's core tsconfig.json * the eslint rule set @nextcloud/eslint-config/typescript was added to prevent: ERROR in [eslint] /app/src/components/AuthTokenSection.vue 35:27 error "@nextcloud/initial-state" is not published n/no-unpublished-import 36:32 error "@nextcloud/l10n" is not published n/no-unpublished-import I can only assume that that rule is disabled in the rule set we extend from or that the module resolution "node" can not find the files. The error actually complains about the module not being part of "dependencies" in package.json, which is the case, however. The internet calls for allowing such modules, which IMO defeats the purpose. The rule is also present in Nextcloud's core config. Build fails with errors like ERROR in /app/src/components/AuthTokenSetup.vue.ts 47:9-14 [tsl] ERROR in /app/src/components/AuthTokenSetup.vue.ts(47,10) TS2339: Property 'reset' does not exist on type 'CreateComponentPublicInstance<{}, { authTokenStore: Store<"auth-token", { tokens: IToken[]; }, {}, { updateToken(token: IToken): Promise<any>; addToken(name: string): Promise<ITokenResponse | null>; deleteToken(token: IToken): Promise<...>; wipeToken(token: IToken): Promise<...>; renameToken(token: IToken, newName: ...'. This hints at Typescript not being able to infer types from the component definition. Related issues: * vuejs/vue#9873 * vuejs/vue#12628 * vuejs/vue#8721 Unsuccessfully attempted proposed solutions: * Declaring return types on methods like: reset(): void { async submit(): Promise<void> { * Using arrow functions Did not work and would introduce new errors anyway * Defining interfaces for the returned component Caused another rabbit hole of more and more required type definitions, that should be infered by the Vue typings anyway
* package.json: add Nextcloud, Vue, typescipt dependencies (from Nextcloud) * remove .ts suffix from import paths (causes build error otherwise) * add declare global to define Nextcloud types. This should be changed to @nextcloud/typings. * annotated import of Nextcloud components (JS) with @ts-expect-error to solve tsc errors. This is most likely due to missing type definitions. Unclear how Nextcloud core made this working. * tsconfig: extend from @vue/tsconfig/tsconfig.json as documented elsewhere and as done in Nextcloud's core tsconfig.json * the eslint rule set @nextcloud/eslint-config/typescript was added to prevent: ERROR in [eslint] /app/src/components/AuthTokenSection.vue 35:27 error "@nextcloud/initial-state" is not published n/no-unpublished-import 36:32 error "@nextcloud/l10n" is not published n/no-unpublished-import I can only assume that that rule is disabled in the rule set we extend from or that the module resolution "node" can not find the files. The error actually complains about the module not being part of "dependencies" in package.json, which is the case, however. The internet calls for allowing such modules, which IMO defeats the purpose. The rule is also present in Nextcloud's core config. Build fails with errors like ERROR in /app/src/components/AuthTokenSetup.vue.ts 47:9-14 [tsl] ERROR in /app/src/components/AuthTokenSetup.vue.ts(47,10) TS2339: Property 'reset' does not exist on type 'CreateComponentPublicInstance<{}, { authTokenStore: Store<"auth-token", { tokens: IToken[]; }, {}, { updateToken(token: IToken): Promise<any>; addToken(name: string): Promise<ITokenResponse | null>; deleteToken(token: IToken): Promise<...>; wipeToken(token: IToken): Promise<...>; renameToken(token: IToken, newName: ...'. This hints at Typescript not being able to infer types from the component definition. Related issues: * vuejs/vue#9873 * vuejs/vue#12628 * vuejs/vue#8721 Unsuccessfully attempted proposed solutions: * Declaring return types on methods like: reset(): void { async submit(): Promise<void> { * Using arrow functions Did not work and would introduce new errors anyway * Defining interfaces for the returned component Caused another rabbit hole of more and more required type definitions, that should be infered by the Vue typings anyway
* package.json: add Nextcloud, Vue, typescipt dependencies (from Nextcloud) * remove .ts suffix from import paths (causes build error otherwise) * add declare global to define Nextcloud types. This should be changed to @nextcloud/typings. * annotated import of Nextcloud components (JS) with @ts-expect-error to solve tsc errors. This is most likely due to missing type definitions. Unclear how Nextcloud core made this working. * tsconfig: extend from @vue/tsconfig/tsconfig.json as documented elsewhere and as done in Nextcloud's core tsconfig.json * the eslint rule set @nextcloud/eslint-config/typescript was added to prevent: ERROR in [eslint] /app/src/components/AuthTokenSection.vue 35:27 error "@nextcloud/initial-state" is not published n/no-unpublished-import 36:32 error "@nextcloud/l10n" is not published n/no-unpublished-import I can only assume that that rule is disabled in the rule set we extend from or that the module resolution "node" can not find the files. The error actually complains about the module not being part of "dependencies" in package.json, which is the case, however. The internet calls for allowing such modules, which IMO defeats the purpose. The rule is also present in Nextcloud's core config. Build fails with errors like ERROR in /app/src/components/AuthTokenSetup.vue.ts 47:9-14 [tsl] ERROR in /app/src/components/AuthTokenSetup.vue.ts(47,10) TS2339: Property 'reset' does not exist on type 'CreateComponentPublicInstance<{}, { authTokenStore: Store<"auth-token", { tokens: IToken[]; }, {}, { updateToken(token: IToken): Promise<any>; addToken(name: string): Promise<ITokenResponse | null>; deleteToken(token: IToken): Promise<...>; wipeToken(token: IToken): Promise<...>; renameToken(token: IToken, newName: ...'. This hints at Typescript not being able to infer types from the component definition. Related issues: * vuejs/vue#9873 * vuejs/vue#12628 * vuejs/vue#8721 Unsuccessfully attempted proposed solutions: * Declaring return types on methods like: reset(): void { async submit(): Promise<void> { * Using arrow functions Did not work and would introduce new errors anyway * Defining interfaces for the returned component Caused another rabbit hole of more and more required type definitions, that should be infered by the Vue typings anyway
* package.json: add Nextcloud, Vue, typescipt dependencies (from Nextcloud) * remove .ts suffix from import paths (causes build error otherwise) * add declare global to define Nextcloud types. This should be changed to @nextcloud/typings. * annotated import of Nextcloud components (JS) with @ts-expect-error to solve tsc errors. This is most likely due to missing type definitions. Unclear how Nextcloud core made this working. * tsconfig: extend from @vue/tsconfig/tsconfig.json as documented elsewhere and as done in Nextcloud's core tsconfig.json * the eslint rule set @nextcloud/eslint-config/typescript was added to prevent: ERROR in [eslint] /app/src/components/AuthTokenSection.vue 35:27 error "@nextcloud/initial-state" is not published n/no-unpublished-import 36:32 error "@nextcloud/l10n" is not published n/no-unpublished-import I can only assume that that rule is disabled in the rule set we extend from or that the module resolution "node" can not find the files. The error actually complains about the module not being part of "dependencies" in package.json, which is the case, however. The internet calls for allowing such modules, which IMO defeats the purpose. The rule is also present in Nextcloud's core config. Build fails with errors like ERROR in /app/src/components/AuthTokenSetup.vue.ts 47:9-14 [tsl] ERROR in /app/src/components/AuthTokenSetup.vue.ts(47,10) TS2339: Property 'reset' does not exist on type 'CreateComponentPublicInstance<{}, { authTokenStore: Store<"auth-token", { tokens: IToken[]; }, {}, { updateToken(token: IToken): Promise<any>; addToken(name: string): Promise<ITokenResponse | null>; deleteToken(token: IToken): Promise<...>; wipeToken(token: IToken): Promise<...>; renameToken(token: IToken, newName: ...'. This hints at Typescript not being able to infer types from the component definition. Related issues: * vuejs/vue#9873 * vuejs/vue#12628 * vuejs/vue#8721 Unsuccessfully attempted proposed solutions: * Declaring return types on methods like: reset(): void { async submit(): Promise<void> { * Using arrow functions Did not work and would introduce new errors anyway * Defining interfaces for the returned component Caused another rabbit hole of more and more required type definitions, that should be infered by the Vue typings anyway
* package.json: add Nextcloud, Vue, typescipt dependencies (from Nextcloud) * remove .ts suffix from import paths (causes build error otherwise) * add declare global to define Nextcloud types. This should be changed to @nextcloud/typings. * annotated import of Nextcloud components (JS) with @ts-expect-error to solve tsc errors. This is most likely due to missing type definitions. Unclear how Nextcloud core made this working. * tsconfig: extend from @vue/tsconfig/tsconfig.json as documented elsewhere and as done in Nextcloud's core tsconfig.json * the eslint rule set @nextcloud/eslint-config/typescript was added to prevent: ERROR in [eslint] /app/src/components/AuthTokenSection.vue 35:27 error "@nextcloud/initial-state" is not published n/no-unpublished-import 36:32 error "@nextcloud/l10n" is not published n/no-unpublished-import I can only assume that that rule is disabled in the rule set we extend from or that the module resolution "node" can not find the files. The error actually complains about the module not being part of "dependencies" in package.json, which is the case, however. The internet calls for allowing such modules, which IMO defeats the purpose. The rule is also present in Nextcloud's core config. Build fails with errors like ERROR in /app/src/components/AuthTokenSetup.vue.ts 47:9-14 [tsl] ERROR in /app/src/components/AuthTokenSetup.vue.ts(47,10) TS2339: Property 'reset' does not exist on type 'CreateComponentPublicInstance<{}, { authTokenStore: Store<"auth-token", { tokens: IToken[]; }, {}, { updateToken(token: IToken): Promise<any>; addToken(name: string): Promise<ITokenResponse | null>; deleteToken(token: IToken): Promise<...>; wipeToken(token: IToken): Promise<...>; renameToken(token: IToken, newName: ...'. This hints at Typescript not being able to infer types from the component definition. Related issues: * vuejs/vue#9873 * vuejs/vue#12628 * vuejs/vue#8721 Unsuccessfully attempted proposed solutions: * Declaring return types on methods like: reset(): void { async submit(): Promise<void> { * Using arrow functions Did not work and would introduce new errors anyway * Defining interfaces for the returned component Caused another rabbit hole of more and more required type definitions, that should be infered by the Vue typings anyway
* package.json: add Nextcloud, Vue, typescipt dependencies (from Nextcloud) * remove .ts suffix from import paths (causes build error otherwise) * add declare global to define Nextcloud types. This should be changed to @nextcloud/typings. * annotated import of Nextcloud components (JS) with @ts-expect-error to solve tsc errors. This is most likely due to missing type definitions. Unclear how Nextcloud core made this working. * tsconfig: extend from @vue/tsconfig/tsconfig.json as documented elsewhere and as done in Nextcloud's core tsconfig.json * the eslint rule set @nextcloud/eslint-config/typescript was added to prevent: ERROR in [eslint] /app/src/components/AuthTokenSection.vue 35:27 error "@nextcloud/initial-state" is not published n/no-unpublished-import 36:32 error "@nextcloud/l10n" is not published n/no-unpublished-import I can only assume that that rule is disabled in the rule set we extend from or that the module resolution "node" can not find the files. The error actually complains about the module not being part of "dependencies" in package.json, which is the case, however. The internet calls for allowing such modules, which IMO defeats the purpose. The rule is also present in Nextcloud's core config. Build fails with errors like ERROR in /app/src/components/AuthTokenSetup.vue.ts 47:9-14 [tsl] ERROR in /app/src/components/AuthTokenSetup.vue.ts(47,10) TS2339: Property 'reset' does not exist on type 'CreateComponentPublicInstance<{}, { authTokenStore: Store<"auth-token", { tokens: IToken[]; }, {}, { updateToken(token: IToken): Promise<any>; addToken(name: string): Promise<ITokenResponse | null>; deleteToken(token: IToken): Promise<...>; wipeToken(token: IToken): Promise<...>; renameToken(token: IToken, newName: ...'. This hints at Typescript not being able to infer types from the component definition. Related issues: * vuejs/vue#9873 * vuejs/vue#12628 * vuejs/vue#8721 Unsuccessfully attempted proposed solutions: * Declaring return types on methods like: reset(): void { async submit(): Promise<void> { * Using arrow functions Did not work and would introduce new errors anyway * Defining interfaces for the returned component Caused another rabbit hole of more and more required type definitions, that should be infered by the Vue typings anyway
COMMIT DESC *** * package.json: add Nextcloud dependencies (from Nextcloud) * remove .ts suffix from import paths (causes build error otherwise) * add declare global to define Nextcloud types. This should be changed to @nextcloud/typings. * annotated import of Nextcloud components (JS) with @ts-expect-error to solve tsc errors. This is most likely due to missing type definitions. Unclear how Nextcloud core made this working. ---------------------- * the eslint rule set @nextcloud/eslint-config/typescript was added to prevent: ERROR in [eslint] /app/src/components/AuthTokenSection.vue 35:27 error "@nextcloud/initial-state" is not published n/no-unpublished-import 36:32 error "@nextcloud/l10n" is not published n/no-unpublished-import I can only assume that that rule is disabled in the rule set we extend from or that the module resolution "node" can not find the files. The error actually complains about the module not being part of "dependencies" in package.json, which is the case, however. The internet calls for allowing such modules, which IMO defeats the purpose. The rule is also present in Nextcloud's core config. ---------------------- Build fails with errors like ERROR in /app/src/components/AuthTokenSetup.vue.ts 47:9-14 [tsl] ERROR in /app/src/components/AuthTokenSetup.vue.ts(47,10) TS2339: Property 'reset' does not exist on type 'CreateComponentPublicInstance<{}, { authTokenStore: Store<"auth-token", { tokens: IToken[]; }, {}, { updateToken(token: IToken): Promise<any>; addToken(name: string): Promise<ITokenResponse | null>; deleteToken(token: IToken): Promise<...>; wipeToken(token: IToken): Promise<...>; renameToken(token: IToken, newName: ...'. This hints at Typescript not being able to infer types from the component definition. Related issues: * vuejs/vue#9873 * vuejs/vue#12628 * vuejs/vue#8721 Unsuccessfully attempted proposed solutions: * Declaring return types on methods like: reset(): void { async submit(): Promise<void> { * Using arrow functions Did not work and would introduce new errors anyway * Defining interfaces for the returned component Caused another rabbit hole of more and more required type definitions, that should be infered by the Vue typings anyway
COMMIT DESC *** * package.json: add Nextcloud dependencies (from Nextcloud) * remove .ts suffix from import paths (causes build error otherwise) * add declare global to define Nextcloud types. This should be changed to @nextcloud/typings. * annotated import of Nextcloud components (JS) with @ts-expect-error to solve tsc errors. This is most likely due to missing type definitions. Unclear how Nextcloud core made this working. ---------------------- * the eslint rule set @nextcloud/eslint-config/typescript was added to prevent: ERROR in [eslint] /app/src/components/AuthTokenSection.vue 35:27 error "@nextcloud/initial-state" is not published n/no-unpublished-import 36:32 error "@nextcloud/l10n" is not published n/no-unpublished-import I can only assume that that rule is disabled in the rule set we extend from or that the module resolution "node" can not find the files. The error actually complains about the module not being part of "dependencies" in package.json, which is the case, however. The internet calls for allowing such modules, which IMO defeats the purpose. The rule is also present in Nextcloud's core config. ---------------------- Build fails with errors like ERROR in /app/src/components/AuthTokenSetup.vue.ts 47:9-14 [tsl] ERROR in /app/src/components/AuthTokenSetup.vue.ts(47,10) TS2339: Property 'reset' does not exist on type 'CreateComponentPublicInstance<{}, { authTokenStore: Store<"auth-token", { tokens: IToken[]; }, {}, { updateToken(token: IToken): Promise<any>; addToken(name: string): Promise<ITokenResponse | null>; deleteToken(token: IToken): Promise<...>; wipeToken(token: IToken): Promise<...>; renameToken(token: IToken, newName: ...'. This hints at Typescript not being able to infer types from the component definition. Related issues: * vuejs/vue#9873 * vuejs/vue#12628 * vuejs/vue#8721 Unsuccessfully attempted proposed solutions: * Declaring return types on methods like: reset(): void { async submit(): Promise<void> { * Using arrow functions Did not work and would introduce new errors anyway * Defining interfaces for the returned component Caused another rabbit hole of more and more required type definitions, that should be infered by the Vue typings anyway
* package.json: add Nextcloud dependencies (from Nextcloud) * main.ts: register pinia Otherwise the following error would be thrown: TypeError: Cannot read properties of undefined (reading '_s') at i (pinia.mjs:1714:20) at setup (AuthTokenList.vue:11:32) at mn (vue.runtime.esm.js:3033:30) at vue.runtime.esm.js:2457:27 ... * remove .ts suffix from import paths (causes build error otherwise) * add declare global to define Nextcloud types. This should be changed to @nextcloud/typings. * annotated import of Nextcloud components (JS) with @ts-expect-error to solve tsc errors. This is most likely due to missing type definitions. Unclear how Nextcloud core made this working. * the eslint rule set @nextcloud/eslint-config/typescript was added to prevent import path errors The build fails with errors like ERROR in /app/src/components/AuthTokenSetup.vue.ts 47:9-14 [tsl] ERROR in /app/src/components/AuthTokenSetup.vue.ts(47,10) TS2339: Property 'reset' does not exist on type 'CreateComponentPublicInstance<{}, { authTokenStore: Store<"auth-token", { tokens: IToken[]; }, {}, { updateToken(token: IToken): Promise<any>; addToken(name: string): Promise<ITokenResponse | null>; deleteToken(token: IToken): Promise<...>; wipeToken(token: IToken): Promise<...>; renameToken(token: IToken, newName: ...'. This hints at Typescript not being able to infer types from the component definition. Related issues: * vuejs/vue#9873 * vuejs/vue#12628 * vuejs/vue#8721 Unsuccessfully attempted proposed solutions: * Declaring return types on methods like: reset(): void { async submit(): Promise<void> { * Using arrow functions Did not work and would introduce new errors anyway * Defining interfaces for the returned component Caused another rabbit hole of more and more required type definitions, that should be infered by the Vue typings anyway
* package.json: add Nextcloud dependencies (from Nextcloud) * main.ts: register pinia Otherwise the following error would be thrown: TypeError: Cannot read properties of undefined (reading '_s') at i (pinia.mjs:1714:20) at setup (AuthTokenList.vue:11:32) at mn (vue.runtime.esm.js:3033:30) at vue.runtime.esm.js:2457:27 ... * remove .ts suffix from import paths (causes build error otherwise) * add declare global to define Nextcloud types. This should be changed to @nextcloud/typings. * annotated import of Nextcloud components (JS) with @ts-expect-error to solve tsc errors. This is most likely due to missing type definitions. Unclear how Nextcloud core made this working. * the eslint rule set @nextcloud/eslint-config/typescript was added to prevent import path errors The build fails with errors like ERROR in /app/src/components/AuthTokenSetup.vue.ts 47:9-14 [tsl] ERROR in /app/src/components/AuthTokenSetup.vue.ts(47,10) TS2339: Property 'reset' does not exist on type 'CreateComponentPublicInstance<{}, { authTokenStore: Store<"auth-token", { tokens: IToken[]; }, {}, { updateToken(token: IToken): Promise<any>; addToken(name: string): Promise<ITokenResponse | null>; deleteToken(token: IToken): Promise<...>; wipeToken(token: IToken): Promise<...>; renameToken(token: IToken, newName: ...'. This hints at Typescript not being able to infer types from the component definition. Related issues: * vuejs/vue#9873 * vuejs/vue#12628 * vuejs/vue#8721 Unsuccessfully attempted proposed solutions: * Declaring return types on methods like: reset(): void { async submit(): Promise<void> { * Using arrow functions Did not work and would introduce new errors anyway * Defining interfaces for the returned component Caused another rabbit hole of more and more required type definitions, that should be infered by the Vue typings anyway
* package.json: add Nextcloud dependencies (from Nextcloud) * main.ts: register pinia Otherwise the following error would be thrown: TypeError: Cannot read properties of undefined (reading '_s') at i (pinia.mjs:1714:20) at setup (AuthTokenList.vue:11:32) at mn (vue.runtime.esm.js:3033:30) at vue.runtime.esm.js:2457:27 ... * remove .ts suffix from import paths (causes build error otherwise) * add declare global to define Nextcloud types. This should be changed to @nextcloud/typings. * annotated import of Nextcloud components (JS) with @ts-expect-error to solve tsc errors. This is most likely due to missing type definitions. Unclear how Nextcloud core made this working. * the eslint rule set @nextcloud/eslint-config/typescript was added to prevent import path errors The build fails with errors like ERROR in /app/src/components/AuthTokenSetup.vue.ts 47:9-14 [tsl] ERROR in /app/src/components/AuthTokenSetup.vue.ts(47,10) TS2339: Property 'reset' does not exist on type 'CreateComponentPublicInstance<{}, { authTokenStore: Store<"auth-token", { tokens: IToken[]; }, {}, { updateToken(token: IToken): Promise<any>; addToken(name: string): Promise<ITokenResponse | null>; deleteToken(token: IToken): Promise<...>; wipeToken(token: IToken): Promise<...>; renameToken(token: IToken, newName: ...'. This hints at Typescript not being able to infer types from the component definition. Related issues: * vuejs/vue#9873 * vuejs/vue#12628 * vuejs/vue#8721 Unsuccessfully attempted proposed solutions: * Declaring return types on methods like: reset(): void { async submit(): Promise<void> { * Using arrow functions Did not work and would introduce new errors anyway * Defining interfaces for the returned component Caused another rabbit hole of more and more required type definitions, that should be infered by the Vue typings anyway Signed-off-by: Thomas Lehmann <t.lehmann@strato.de>
* package.json: add Nextcloud dependencies (from Nextcloud) * main.ts: register pinia Otherwise the following error would be thrown: TypeError: Cannot read properties of undefined (reading '_s') at i (pinia.mjs:1714:20) at setup (AuthTokenList.vue:11:32) at mn (vue.runtime.esm.js:3033:30) at vue.runtime.esm.js:2457:27 ... * remove .ts suffix from import paths (causes build error otherwise) * add declare global to define Nextcloud types. This should be changed to @nextcloud/typings. * annotated import of Nextcloud components (JS) with @ts-expect-error to solve tsc errors. This is most likely due to missing type definitions. Unclear how Nextcloud core made this working. * the eslint rule set @nextcloud/eslint-config/typescript was added to prevent import path errors The build fails with errors like ERROR in /app/src/components/AuthTokenSetup.vue.ts 47:9-14 [tsl] ERROR in /app/src/components/AuthTokenSetup.vue.ts(47,10) TS2339: Property 'reset' does not exist on type 'CreateComponentPublicInstance<{}, { authTokenStore: Store<"auth-token", { tokens: IToken[]; }, {}, { updateToken(token: IToken): Promise<any>; addToken(name: string): Promise<ITokenResponse | null>; deleteToken(token: IToken): Promise<...>; wipeToken(token: IToken): Promise<...>; renameToken(token: IToken, newName: ...'. This hints at Typescript not being able to infer types from the component definition. Related issues: * vuejs/vue#9873 * vuejs/vue#12628 * vuejs/vue#8721 Unsuccessfully attempted proposed solutions: * Declaring return types on methods like: reset(): void { async submit(): Promise<void> { * Using arrow functions Did not work and would introduce new errors anyway * Defining interfaces for the returned component Caused another rabbit hole of more and more required type definitions, that should be infered by the Vue typings anyway Signed-off-by: Thomas Lehmann <t.lehmann@strato.de>
Version
2.6.10
Reproduction link
https://github.com/Patcher56/ts3.4.x-vuejs-issue
Steps to reproduce
vue create test-ts
src/components/HelloWorld.vue
What is expected?
No errors (as the data is defined)
What is actually happening?
Typescript error 2339 telling me
Property 'test' does not exist on type 'CombinedVueInstance<Vue, {}, {}, {}, Readonly<{ msg: string; }>>'.
I think this has something to do with the changed type inference in Typescript 3.4.x.
Important: Change vetur settings to use workspace dependencies to show errors directly in vscode, else you will only get the error when using
yarn serve
.The text was updated successfully, but these errors were encountered: