Subscribe on changes!

`this` type is broken in computed options.

avatar
Jan 14th 2021

Version

3.0.5

Reproduction link

https://codesandbox.io/s/pensive-carson-ozwfq?file=/src/index.ts

Steps to reproduce

image

What is expected?

this.p should be a string

What is actually happening?

this type doesn't work well

avatar
Jan 14th 2021

This can be reproduced by (from @Justineo): https://www.typescriptlang.org/play?#code/C4TwDgpgBA8mwGcA8AVAfFAvFA3gKCigBMBDYEgCgEoAuKFAbgKgFsJgALAeyITv0KEA2gGs6CYACcAlgDsA5gF061LBhKyQTQgF8oAMnodpCFOAio0THUzwAzAK6yAxsGldZUO7MsUu8OjhES1ooADcuaSJcHTx7WQoBYjJKKlxmQkl2B0lPJMFwkgAbBwg6AEYMqBtmHQAaZjZOHj50grsuLlV8wU4TADow4tLbAsIAenGoLOAczz6EQeHocYAqKAADBY2oACMIZy42BE2nEVkuAHdPVfGq2N08HSomIA

I think @edison1105 's PR is a workaround and may not solve the root cause, because the Function type is just an interface:

interface Function {
    /**
     * Returns the name of the function. Function names are read-only and can not be changed.
     */
    readonly name: string;
}

Does anyone have other insights?

avatar
Jan 14th 2021

Oh, missed the information here: https://vuejs.org/v2/guide/typescript.html#Annotating-Return-Types, this issue can be closed.

Edit: related https://github.com/vuejs/vetur/issues/2373

avatar
Jan 14th 2021

I think you should type the computed property return type like said above