当前位置:  开发笔记 > 编程语言 > 正文

声明泛型类型的const

如何解决《声明泛型类型的const》经验,为你挑选了1个好方法。



1> Titian Cerni..:

作为函数的泛型类型和作为泛型函数的类型之间存在差异.

您定义的是一个泛型类型,它是一个函数.这意味着我们可以将其分配给具有指定泛型类型的consts:

type FunctionType = (value: TValue) => void;
const bar: FunctionType = (value) => { // value is number
}

要定义作为泛型函数的类型,我们需要将type参数放在参数列表之前

type FunctionType = (value: TValue) => void;
const bar: FunctionType = (value) => { // generic function
}

推荐阅读
拾味湖
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有