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

[Bug Report] how to use validateField in typescript #8756

Closed
mu-yu opened this issue Dec 11, 2017 · 3 comments · Fixed by #17314
Closed

[Bug Report] how to use validateField in typescript #8756

mu-yu opened this issue Dec 11, 2017 · 3 comments · Fixed by #17314

Comments

@mu-yu
Copy link
Contributor

mu-yu commented Dec 11, 2017

Element UI version

0.1.0

OS/Browsers version

typescript: 2.6.2

Vue version

2.5.9

Reproduction Link

https://jsfiddle.net/mmx38qxw/

Steps to reproduce

使用typescript配合element-ui,在表单验证某个字段的时候使用了如下方法:

(this.$refs[formRef] as ElForm).validateField('packageNames', function(errMsg: string): void {})

但是会报错:TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'void' has no compatible call signatures.

What is Expected?

callback应该为可选项,且可以传入简单的箭头函数

What is actually happening?

callback为必选项,且传入简单的箭头函数会报错:
TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'void' has no compatible call signatures.

@element-bot
Copy link
Member

Translation of this issue:

Element UI version

0.1.0

OS/Browsers version

Typescript: 2.6.2

Vue version

2.5.9

Reproduction Link

https://jsfiddle.net/mmx38qxw/

Steps to reproduce

Using typescript with element-ui, the following method is used to verify a field in the form:

(this.$refs[formRef] as ElForm.ValidateField ('packageNames'), function (errMsg: string): void {}). But there will be a mistake:TS2349: Cannot invoke an expression whose type lacks a call signature. Type

What is Expected?

Callback should be optional and can be introduced into a simple arrow function

What is actually happening?

Callback is a necessary option, and the introduction of a simple arrowhead function will be wrong:

` TS2349: Cannot invoke an expression whose type lacks a call signature. Type

@baixiaoji
Copy link

I meet the same problem

@tudi2d
Copy link

tudi2d commented Jun 25, 2019

I´m facing the same problem. Writing this.$refs["form"]["validateField"]("packageNames") avoids the type checking. This is not a solution but a work around.

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

Successfully merging a pull request may close this issue.

4 participants