Skip to content
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

Typings with Typescript 2.7.1 #7640

Closed
AntoineEsteve opened this issue Feb 13, 2018 · 5 comments
Closed

Typings with Typescript 2.7.1 #7640

AntoineEsteve opened this issue Feb 13, 2018 · 5 comments

Comments

@AntoineEsteve
Copy link

AntoineEsteve commented Feb 13, 2018

Version

2.5.13

Steps to reproduce

Create a simple component using Typescript:

import Vue from "vue"

Vue.extend({
    props: {
        myProp: {
            type: Array,
        },
    },
    computed: {
        myComputed(): string {
            return "hello"
        },
        otherComputed(): string {
            return this.myComputed
        },
    },
})

We have the following error:

 TS2322: Type '(() => any) | ComputedOptions<any>' is not assignable to type 'string'.
  Type '() => any' is not assignable to type 'string'.

If we change the type of the prop to String, Number or smtg else we don't have this problem anymore

What is expected?

No error

What is actually happening?

Errors


This problem was not happening with the previous Typescript versions (at least 2.5.2)

@HerringtonDarkholme
Copy link
Member

I believe this is a bug in TypeScript. For now you can cast it.

import Vue, {PropOptions} from "vue"

Vue.extend({
    props: {
        myProp: {
            type: Array,
        } as PropOptions<any[]>,
    },
    computed: {
        myComputed(): string {
            return "hello"
        },
        otherComputed(): string {
            return this.myComputed
        },
    },
})

@kunalkundaje
Copy link

@HerringtonDarkholme Do you know if there's a specific issue in https://github.com/Microsoft/TypeScript/issues that we can track related to this?

@HerringtonDarkholme
Copy link
Member

I guess this is the problem of overloading, again.

Commenting out the last of extend overloading signature solves this.

@HerringtonDarkholme
Copy link
Member

HerringtonDarkholme commented Mar 11, 2018

Boiled down reproduction:

type Prop<T> = { (): T }

declare function test<T>(a: Prop<T>): T
declare function test(a: Prop<any>): {} // toggle this line

var a = test(Array)

a.push

@HerringtonDarkholme
Copy link
Member

This issue is now tracked in microsoft/TypeScript#22471.

There is nothing Vue can do for now. Let's close this and wait for TS team to fix it.

For now you can manually annotate the prop definition as shown above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants