泛型
,
Hello World
function 识别(arg:任何):任何{,,,,return 参数; }
,
function identity(arg: T):, T {,,, return 参数; }
,
let output =, identify(qwe);
,
let output =,识别(qwe);
,
泛型变量
function identify(arg: T):, T { ,,,console.log (arg.length);//,错误:,T 并't have . length ,,,return 参数; }
,
function identify(arg: T []):, T [], { ,,,console.log (arg.length);//,错误:,T 并't have . length ,,,return 参数; }
,
泛型类型
function identify(arg: T):, T {,,, return 参数; } let myIdentify: & lt;标签;(arg: U),=祝辞,U =,识别;
,
interface GenericIdnetify{ ,,,(arg: T):, T; }function identity< T> (arg: T): T, {,,, return 参数; } let myGenericidentify:, GenericIdnetify
,
泛型类
class GenericNumber, { ,,,zeroValue:, T; ,,,添加:,(x: T,, y,, T),=祝辞,T; } let myGenericNumber =, new GenericNumber (); 时间=myGenericNumber.zeroValue 0; myGenericNumber.add =,函数(x, y), {, return x  +, y,,},
,
泛型约束
interface 纵向{ ,,,长度:,数量; }function identity< T extends  lengthwise> (arg: T): T, { ,,,console.log (arg.length);,,,, return 参数; } 身份(123);,//erroridentity (qwe);,//真正的
打印稿入门——泛型