我有一个变量,可以是一个对象数组,一个数字数组,一个嵌套的对象数组或一个嵌套的数字数组。我的功能依次处理这些情况,但我尝试使用Facebook流程使我的代码类型安全,并且我得到了一个不兼容的类型错误。
type Data = number[] | {}[] | Array<{}[]> | Array<number[]>
function parseData(data = Data) {
...
}
当我跑步时,我得到了
build/js/helpers.js:2
2: type Data = number[] | {}[] | Array<{}[]> | Array<number[]>
^^^^^^ number. This type is incompatible with
2: type Data = number[] | {}[] | Array<{}[]> | Array<number[]>
^^ object type
build/js/helpers.js:2
2: type Data = number[] | {}[] | Array<{}[]> | Array<number[]>
^^^^^^ number. This type is incompatible with
2: type Data = number[] | {}[] | Array<{}[]> | Array<number[]>
build/js/helpers.js:2
2: type Data = number[] | {}[] | Array<{}[]> | Array<number[]>
^^^^^^ number. This type is incompatible with
2: type Data = number[] | {}[] | Array<{}[]> | Array<number[]>
^^^^^^^^ array type
build/js/helpers.js:2
2: type Data = number[] | {}[] | Array<{}[]> | Array<number[]>
^^ object type. This type is incompatible with
2: type Data = number[] | {}[] | Array<{}[]> | Array<number[]>
^^^^^^ number
build/js/helpers.js:2
2: type Data = number[] | {}[] | Array<{}[]> | Array<number[]>
^^^^ array type. This type is incompatible with
2: type Data = number[] | {}[] | Array<{}[]> | Array<number[]>
^^^^^^ number
build/js/helpers.js:2
2: type Data = number[] | {}[] | Array<{}[]> | Array<number[]>
^^^^^^^^ array type. This type is incompatible with
2: type Data = number[] | {}[] | Array<{}[]> | Array<number[]>
^^^^^^ number
我知道它说一个数字数组的变量不能是一个对象数组,也不能是一个数组数组,但我不知道如何输入这个变量。
答案 0 :(得分:1)
您在参数中使用了错误的类型。所以这一行:
def professor_classes(self):
return Classes.objects.filter(professor=self.professor)
应替换为此行:
Question
如果使用赋值运算符,则基本上为参数定义默认值。因此,您需要使用冒号字符来标记特定类型的参数,而不是赋值运算符。
至少我在在线流量检查器here
中没有出现更多错误