Skip to content

TS typings of components should be more useful #3220

Open
@CarterLi

Description

@CarterLi
  • I have searched the issues of this repository and believe that this is not a duplicate.

What problem does this feature solve?

(this.$refs.input as Input).focus();

results in error:

ERROR in src/views/home/home.tsx:16:28
TS2749: 'Input' refers to a value, but is being used as a type here. Did you mean 'typeof Input'?
14 |   methods: {
15 |     fn() {
> 16 |       (this.$refs.input as Input).focus();
|                            ^^^^^
17 |     }
18 |   }
19 | });

Instead, you have to write the verbose and not-newbie-friendly code:

(this.$refs.input as InstanceType<typeof Input>).focus();

That works with vscode intellisense and type checking.

What does the proposed API look like?

(this.$refs.input as Input).focus();

should work as the old version does.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions