Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript TS:如何在声明中使用'this.something'_Javascript_Typescript - Fatal编程技术网

Javascript TS:如何在声明中使用'this.something'

Javascript TS:如何在声明中使用'this.something',javascript,typescript,Javascript,Typescript,我正在使用Vue+TypeScript,但我相信这只与TypeScript有关 因为我被迫使用 export default Vue.extend({ data() { return { fields: { name: schema.string().required(), age: schema.number().required().oneOf([10, 20, 30]) } } }, methods: {

我正在使用Vue+TypeScript,但我相信这只与TypeScript有关

因为我被迫使用

export default Vue.extend({
  data() {
    return {
      fields: {
        name: schema.string().required(),
        age: schema.number().required().oneOf([10, 20, 30])
      }
    }
  },
  methods: {
    send(values: any) {
      const fields = this.fields

      type Fields = TypeOf<typeof fields>

      users.create(values as Fields)
    }
  }
})
导出默认Vue.extend({
数据(){
返回{
字段:{
名称:schema.string().required(),
年龄:schema.number().required().oneOf([10,20,30])
}
}
},
方法:{
发送(值:任意){
常量字段=this.fields
类型字段=类型字段
创建(值作为字段)
}
}
})
我想如何使用

构造功能范围的另一个示例


有没有任何方法可以使用
typeof this.something而不必声明变量来存储
this.someting的值?

typeof
应该可以使用。只能对标识符(变量名)或其属性使用
typeof
。@AlekseyL。但我需要的是将某个变量的类型传递到我创建的
TypeOf
。示例
InferType
typeof this['variableHere']
不起作用,因为
this
未知,请看这里是要测试的代码哦,我明白了
作为一种类型只能在类/接口中使用在上一个示例中,您使用的是
内部箭头函数。您希望此
为哪种类型?