{"id":3248,"date":"2020-07-13T08:52:00","date_gmt":"2020-07-13T08:52:00","guid":{"rendered":"http:\/\/the-codest.localhost\/blog\/generics-in-typescript\/"},"modified":"2026-04-24T11:39:03","modified_gmt":"2026-04-24T11:39:03","slug":"%ce%b3%ce%b5%ce%bd%ce%b9%ce%ba%ce%ad%cf%82-%cf%83%ce%b5-typescript","status":"publish","type":"post","link":"https:\/\/thecodest.co\/el\/blog\/generics-in-typescript\/","title":{"rendered":"\u0393\u03b5\u03bd\u03cc\u03c3\u03b7\u03bc\u03b1 \u03c3\u03c4\u03bf TypeScript"},"content":{"rendered":"<p>\u039f\u03b9 \u03b3\u03b5\u03bd\u03b9\u03ba\u03ad\u03c2 \u03bc\u03c0\u03bf\u03c1\u03bf\u03cd\u03bd \u03bd\u03b1 \u03c7\u03c1\u03b7\u03c3\u03b9\u03bc\u03bf\u03c0\u03bf\u03b9\u03b7\u03b8\u03bf\u03cd\u03bd \u03c3\u03b5 \u03c3\u03c5\u03bd\u03b4\u03c5\u03b1\u03c3\u03bc\u03cc \u03bc\u03b5 \u03c3\u03c5\u03bd\u03b1\u03c1\u03c4\u03ae\u03c3\u03b5\u03b9\u03c2 (\u03b4\u03b7\u03bc\u03b9\u03bf\u03c5\u03c1\u03b3\u03af\u03b1 \u03b3\u03b5\u03bd\u03b9\u03ba\u03ae\u03c2 \u03c3\u03c5\u03bd\u03ac\u03c1\u03c4\u03b7\u03c3\u03b7\u03c2), \u03ba\u03bb\u03ac\u03c3\u03b5\u03b9\u03c2 (\u03b4\u03b7\u03bc\u03b9\u03bf\u03c5\u03c1\u03b3\u03af\u03b1 \u03b3\u03b5\u03bd\u03b9\u03ba\u03ae\u03c2 \u03ba\u03bb\u03ac\u03c3\u03b7\u03c2) \u03ba\u03b1\u03b9 \u03b4\u03b9\u03b5\u03c0\u03b1\u03c6\u03ad\u03c2 (\u03b4\u03b7\u03bc\u03b9\u03bf\u03c5\u03c1\u03b3\u03af\u03b1 \u03b3\u03b5\u03bd\u03b9\u03ba\u03ae\u03c2 \u03b4\u03b9\u03b5\u03c0\u03b1\u03c6\u03ae\u03c2).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u0392\u03b1\u03c3\u03b9\u03ba\u03ae \u03c7\u03c1\u03ae\u03c3\u03b7<\/h2>\n\n\n\n<p>\u03a0\u03b9\u03b8\u03b1\u03bd\u03cc\u03bd \u03bd\u03b1 \u03ad\u03c7\u03b5\u03c4\u03b5 \u03c7\u03c1\u03b7\u03c3\u03b9\u03bc\u03bf\u03c0\u03bf\u03b9\u03ae\u03c3\u03b5\u03b9 generics \u03c3\u03c4\u03bf \u03c0\u03b1\u03c1\u03b5\u03bb\u03b8\u03cc\u03bd \u03b1\u03ba\u03cc\u03bc\u03b1 \u03ba\u03b1\u03b9 \u03c7\u03c9\u03c1\u03af\u03c2 \u03bd\u03b1 \u03c4\u03bf \u03b3\u03bd\u03c9\u03c1\u03af\u03b6\u03b5\u03c4\u03b5 - \u03b7 \u03c0\u03b9\u03bf \u03c3\u03c5\u03bd\u03b7\u03b8\u03b9\u03c3\u03bc\u03ad\u03bd\u03b7 \u03c7\u03c1\u03ae\u03c3\u03b7 generics \u03b5\u03af\u03bd\u03b1\u03b9 \u03b7 \u03b4\u03ae\u03bb\u03c9\u03c3\u03b7 \u03b5\u03bd\u03cc\u03c2 \u03c0\u03af\u03bd\u03b1\u03ba\u03b1:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"typescript\" class=\"language-typescript\">const myArray: string[],<\/code><\/pre>\n\n\n\n<p>\u0394\u03b5\u03bd \u03b5\u03af\u03bd\u03b1\u03b9 \u03c0\u03bf\u03bb\u03cd \u03b9\u03b4\u03b9\u03b1\u03af\u03c4\u03b5\u03c1\u03bf \u03bc\u03b5 \u03c4\u03b7\u03bd \u03c0\u03c1\u03ce\u03c4\u03b7 \u03bc\u03b1\u03c4\u03b9\u03ac, \u03b1\u03c0\u03bb\u03ac \u03b4\u03b7\u03bb\u03ce\u03bd\u03bf\u03c5\u03bc\u03b5 <code>myArray<\/code> \u03c9\u03c2 \u03c0\u03af\u03bd\u03b1\u03ba\u03b1\u03c2 \u03c3\u03c5\u03bc\u03b2\u03bf\u03bb\u03bf\u03c3\u03b5\u03b9\u03c1\u03ce\u03bd, \u03b1\u03bb\u03bb\u03ac \u03b5\u03af\u03bd\u03b1\u03b9 \u03c4\u03bf \u03af\u03b4\u03b9\u03bf \u03bc\u03b5 \u03bc\u03b9\u03b1 \u03b3\u03b5\u03bd\u03b9\u03ba\u03ae \u03b4\u03ae\u03bb\u03c9\u03c3\u03b7:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"typescript\" class=\"language-typescript\">const myArray: Array,<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u039a\u03c1\u03b1\u03c4\u03ce\u03bd\u03c4\u03b1\u03c2 \u03c4\u03b1 \u03c0\u03c1\u03ac\u03b3\u03bc\u03b1\u03c4\u03b1 \u03c1\u03b7\u03c4\u03ac<\/h2>\n\n\n\n<p>\u0391\u03c2 \u03be\u03b5\u03ba\u03b9\u03bd\u03ae\u03c3\u03bf\u03c5\u03bc\u03b5 \u03bc\u03b5 \u03ad\u03bd\u03b1 \u03c0\u03bf\u03bb\u03cd \u03b1\u03c0\u03bb\u03cc \u03c0\u03b1\u03c1\u03ac\u03b4\u03b5\u03b9\u03b3\u03bc\u03b1 - \u03c0\u03ce\u03c2 \u03b8\u03b1 \u03bc\u03c0\u03bf\u03c1\u03bf\u03cd\u03c3\u03b1\u03bc\u03b5 \u03bd\u03b1 \u03bc\u03b5\u03c4\u03b1\u03c6\u03ad\u03c1\u03bf\u03c5\u03bc\u03b5 \u03b1\u03c5\u03c4\u03ae \u03c4\u03b7 \u03b2\u03b1\u03bd\u03af\u03bb\u03b9\u03b1 <a href=\"https:\/\/thecodest.co\/el\/blog\/hire-vue-js-developers\/\">JS<\/a> \u03c3\u03c5\u03bd\u03ac\u03c1\u03c4\u03b7\u03c3\u03b7 \u03b3\u03b9\u03b1 \u03bd\u03b1 <a href=\"https:\/\/thecodest.co\/el\/dictionary\/typescript-developer\/\">TypeScript<\/a>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"typescript\" class=\"language-typescript\">function getPrefiledArray(filler, length) {\n    return (new Array(length)).fill(filler),\n}<\/code><\/pre>\n\n\n\n<p>\u0391\u03c5\u03c4\u03ae \u03b7 \u03c3\u03c5\u03bd\u03ac\u03c1\u03c4\u03b7\u03c3\u03b7 \u03b8\u03b1 \u03b5\u03c0\u03b9\u03c3\u03c4\u03c1\u03ad\u03c8\u03b5\u03b9 \u03c0\u03af\u03bd\u03b1\u03ba\u03b1 \u03b3\u03b5\u03bc\u03ac\u03c4\u03bf \u03bc\u03b5 \u03c4\u03b7 \u03b4\u03b5\u03b4\u03bf\u03bc\u03ad\u03bd\u03b7 \u03c0\u03bf\u03c3\u03cc\u03c4\u03b7\u03c4\u03b1 \u03c4\u03c9\u03bd <code>\u03c0\u03bb\u03b7\u03c1\u03c9\u03c4\u03b9\u03ba\u03cc<\/code>, \u03bf\u03c0\u03cc\u03c4\u03b5 <code>\u03bc\u03ae\u03ba\u03bf\u03c2<\/code> \u03b8\u03b1 \u03b5\u03af\u03bd\u03b1\u03b9 <code>\u03b1\u03c1\u03b9\u03b8\u03bc\u03cc\u03c2<\/code> \u03ba\u03b1\u03b9 \u03bf\u03bb\u03cc\u03ba\u03bb\u03b7\u03c1\u03b7 \u03b7 \u03c3\u03c5\u03bd\u03ac\u03c1\u03c4\u03b7\u03c3\u03b7 \u03b8\u03b1 \u03b5\u03c0\u03b9\u03c3\u03c4\u03c1\u03ad\u03c8\u03b5\u03b9 \u03c0\u03af\u03bd\u03b1\u03ba\u03b1 <code>\u03c0\u03bb\u03b7\u03c1\u03c9\u03c4\u03b9\u03ba\u03cc<\/code> - \u03b1\u03bb\u03bb\u03ac \u03c4\u03b9 \u03b5\u03af\u03bd\u03b1\u03b9 \u03c4\u03bf \u03c5\u03bb\u03b9\u03ba\u03cc \u03c0\u03bb\u03ae\u03c1\u03c9\u03c3\u03b7\u03c2; \u03a3\u03b5 \u03b1\u03c5\u03c4\u03cc \u03c4\u03bf \u03c3\u03b7\u03bc\u03b5\u03af\u03bf \u03bc\u03c0\u03bf\u03c1\u03b5\u03af \u03bd\u03b1 \u03b5\u03af\u03bd\u03b1\u03b9 \u03bf\u03c4\u03b9\u03b4\u03ae\u03c0\u03bf\u03c4\u03b5, \u03bf\u03c0\u03cc\u03c4\u03b5 \u03bc\u03b9\u03b1 \u03b5\u03c0\u03b9\u03bb\u03bf\u03b3\u03ae \u03b5\u03af\u03bd\u03b1\u03b9 \u03bd\u03b1 \u03c7\u03c1\u03b7\u03c3\u03b9\u03bc\u03bf\u03c0\u03bf\u03b9\u03ae\u03c3\u03b5\u03c4\u03b5 <code>\u03bf\u03c0\u03bf\u03b9\u03bf\u03b4\u03ae\u03c0\u03bf\u03c4\u03b5<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"typescript\" class=\"language-typescript\">function getPrefiledArray(filler: any, length: number): any[] {\n    return (new Array(length)).fill(filler),\n}<\/code><\/pre>\n\n\n\n<p>\u03a7\u03c1\u03ae\u03c3\u03b7 \u03c4\u03bf\u03c5 <code>\u03bf\u03c0\u03bf\u03b9\u03bf\u03b4\u03ae\u03c0\u03bf\u03c4\u03b5<\/code> \u03b5\u03af\u03bd\u03b1\u03b9 \u03c3\u03af\u03b3\u03bf\u03c5\u03c1\u03b1 \u03b3\u03b5\u03bd\u03b9\u03ba\u03ae - \u03bc\u03c0\u03bf\u03c1\u03bf\u03cd\u03bc\u03b5 \u03bd\u03b1 \u03c0\u03b5\u03c1\u03ac\u03c3\u03bf\u03c5\u03bc\u03b5 \u03ba\u03c5\u03c1\u03b9\u03bf\u03bb\u03b5\u03ba\u03c4\u03b9\u03ba\u03ac \u03bf\u03c4\u03b9\u03b4\u03ae\u03c0\u03bf\u03c4\u03b5, \u03bf\u03c0\u03cc\u03c4\u03b5 \u03b7 \"\u03b5\u03c1\u03b3\u03b1\u03c3\u03af\u03b1 \u03bc\u03b5 \u03ad\u03bd\u03b1\u03bd \u03b1\u03c1\u03b9\u03b8\u03bc\u03cc \u03c4\u03cd\u03c0\u03c9\u03bd \u03b1\u03bd\u03c4\u03af \u03b3\u03b9\u03b1 \u03ad\u03bd\u03b1\u03bd \u03c4\u03cd\u03c0\u03bf\" \u03b1\u03c0\u03cc \u03c4\u03bf\u03bd \u03bf\u03c1\u03b9\u03c3\u03bc\u03cc \u03ba\u03b1\u03bb\u03cd\u03c0\u03c4\u03b5\u03c4\u03b1\u03b9 \u03c0\u03bb\u03ae\u03c1\u03c9\u03c2, \u03b1\u03bb\u03bb\u03ac \u03c7\u03ac\u03bd\u03bf\u03c5\u03bc\u03b5 \u03c4\u03b7 \u03c3\u03cd\u03bd\u03b4\u03b5\u03c3\u03b7 \u03bc\u03b5\u03c4\u03b1\u03be\u03cd \u03c4\u03c9\u03bd <code>\u03c0\u03bb\u03b7\u03c1\u03c9\u03c4\u03b9\u03ba\u03cc<\/code> \u03c4\u03cd\u03c0\u03bf \u03ba\u03b1\u03b9 \u03c4\u03bf\u03bd \u03c4\u03cd\u03c0\u03bf \u03b5\u03c0\u03b9\u03c3\u03c4\u03c1\u03bf\u03c6\u03ae\u03c2. \u03a3\u03b5 \u03b1\u03c5\u03c4\u03ae \u03c4\u03b7\u03bd \u03c0\u03b5\u03c1\u03af\u03c0\u03c4\u03c9\u03c3\u03b7, \u03b8\u03ad\u03bb\u03bf\u03c5\u03bc\u03b5 \u03bd\u03b1 \u03b5\u03c0\u03b9\u03c3\u03c4\u03c1\u03ad\u03c8\u03bf\u03c5\u03bc\u03b5 \u03ba\u03ac\u03c0\u03bf\u03b9\u03bf \u03ba\u03bf\u03b9\u03bd\u03cc \u03c0\u03c1\u03ac\u03b3\u03bc\u03b1, \u03ba\u03b1\u03b9 \u03bc\u03c0\u03bf\u03c1\u03bf\u03cd\u03bc\u03b5 \u03bd\u03b1 \u03bf\u03c1\u03af\u03c3\u03bf\u03c5\u03bc\u03b5 \u03c1\u03b7\u03c4\u03ac \u03b1\u03c5\u03c4\u03cc \u03c4\u03bf \u03ba\u03bf\u03b9\u03bd\u03cc \u03c0\u03c1\u03ac\u03b3\u03bc\u03b1 \u03c9\u03c2 <strong>\u03c0\u03b1\u03c1\u03ac\u03bc\u03b5\u03c4\u03c1\u03bf\u03c2 \u03c4\u03cd\u03c0\u03bf\u03c5<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"typescript\" class=\"language-typescript\">function getPrefiledArray(filler: T, length: number): T[] {\n    return (new Array(length)).fill(filler),\n}<\/code><\/pre>\n\n\n\n<p>\u03ba\u03b1\u03b9 \u03c7\u03c1\u03b7\u03c3\u03b9\u03bc\u03bf\u03c0\u03bf\u03b9\u03ae\u03c3\u03c4\u03b5 \u03c4\u03bf \u03c9\u03c2 \u03b5\u03be\u03ae\u03c2:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"typescript\" class=\"language-typescript\">const prefilledArray = getPrefiledArray(0, 10),<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u0393\u03b5\u03bd\u03b9\u03ba\u03bf\u03af \u03c0\u03b5\u03c1\u03b9\u03bf\u03c1\u03b9\u03c3\u03bc\u03bf\u03af<\/h2>\n\n\n\n<p>\u0391\u03c2 \u03b4\u03bf\u03cd\u03bc\u03b5 \u03b4\u03b9\u03b1\u03c6\u03bf\u03c1\u03b5\u03c4\u03b9\u03ba\u03ad\u03c2, \u03c0\u03b9\u03b8\u03b1\u03bd\u03ce\u03c2 \u03c0\u03b9\u03bf \u03c3\u03c5\u03bd\u03b7\u03b8\u03b9\u03c3\u03bc\u03ad\u03bd\u03b5\u03c2 \u03c0\u03b5\u03c1\u03b9\u03c0\u03c4\u03ce\u03c3\u03b5\u03b9\u03c2. \u0393\u03b9\u03b1\u03c4\u03af \u03c7\u03c1\u03b7\u03c3\u03b9\u03bc\u03bf\u03c0\u03bf\u03b9\u03bf\u03cd\u03bc\u03b5 \u03c4\u03cd\u03c0\u03bf\u03c5\u03c2 \u03c3\u03b5 \u03c3\u03c5\u03bd\u03b1\u03c1\u03c4\u03ae\u03c3\u03b5\u03b9\u03c2; \u0393\u03b9\u03b1 \u03bc\u03ad\u03bd\u03b1, \u03b5\u03af\u03bd\u03b1\u03b9 \u03b3\u03b9\u03b1 \u03bd\u03b1 \u03b4\u03b9\u03b1\u03c3\u03c6\u03b1\u03bb\u03af\u03c3\u03c9 \u03cc\u03c4\u03b9 \u03c4\u03b1 \u03bf\u03c1\u03af\u03c3\u03bc\u03b1\u03c4\u03b1 \u03c0\u03bf\u03c5 \u03b8\u03b1 \u03c0\u03b5\u03c1\u03ac\u03c3\u03bf\u03c5\u03bd \u03c3\u03c4\u03b7 \u03c3\u03c5\u03bd\u03ac\u03c1\u03c4\u03b7\u03c3\u03b7 \u03b8\u03b1 \u03ad\u03c7\u03bf\u03c5\u03bd \u03ba\u03ac\u03c0\u03bf\u03b9\u03b5\u03c2 \u03b9\u03b4\u03b9\u03cc\u03c4\u03b7\u03c4\u03b5\u03c2 \u03bc\u03b5 \u03c4\u03b9\u03c2 \u03bf\u03c0\u03bf\u03af\u03b5\u03c2 \u03b8\u03ad\u03bb\u03c9 \u03bd\u03b1 \u03b1\u03bb\u03bb\u03b7\u03bb\u03b5\u03c0\u03b9\u03b4\u03c1\u03ac\u03c3\u03c9.<\/p>\n\n\n\n<p>\u0393\u03b9\u03b1 \u03ac\u03bb\u03bb\u03b7 \u03bc\u03b9\u03b1 \u03c6\u03bf\u03c1\u03ac \u03b1\u03c2 \u03c0\u03c1\u03bf\u03c3\u03c0\u03b1\u03b8\u03ae\u03c3\u03bf\u03c5\u03bc\u03b5 \u03bd\u03b1 \u03bc\u03b5\u03c4\u03b1\u03c6\u03ad\u03c1\u03bf\u03c5\u03bc\u03b5 \u03bc\u03b9\u03b1 \u03b1\u03c0\u03bb\u03ae \u03c3\u03c5\u03bd\u03ac\u03c1\u03c4\u03b7\u03c3\u03b7 JS vanilla \u03c3\u03c4\u03bf TS.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"typescript\" class=\"language-typescript\">function getLength(thing) {\n    return thing.length,\n}<\/code><\/pre>\n\n\n\n<p>\u0388\u03c7\u03bf\u03c5\u03bc\u03b5 \u03ad\u03bd\u03b1 \u03bc\u03b7 \u03c4\u03b5\u03c4\u03c1\u03b9\u03bc\u03bc\u03ad\u03bd\u03bf \u03b1\u03af\u03bd\u03b9\u03b3\u03bc\u03b1 - \u03c0\u03ce\u03c2 \u03bd\u03b1 \u03b5\u03be\u03b1\u03c3\u03c6\u03b1\u03bb\u03af\u03c3\u03bf\u03c5\u03bc\u03b5 \u03cc\u03c4\u03b9 \u03c4\u03bf \u03c0\u03c1\u03ac\u03b3\u03bc\u03b1 \u03ad\u03c7\u03b5\u03b9 \u03bc\u03b9\u03b1 <code>\u03bc\u03ae\u03ba\u03bf\u03c2<\/code> \u03b9\u03b4\u03b9\u03cc\u03c4\u03b7\u03c4\u03b1, \u03ba\u03b1\u03b9 \u03b7 \u03c0\u03c1\u03ce\u03c4\u03b7 \u03c3\u03ba\u03ad\u03c8\u03b7 \u03bc\u03c0\u03bf\u03c1\u03b5\u03af \u03bd\u03b1 \u03b5\u03af\u03bd\u03b1\u03b9 \u03bd\u03b1 \u03ba\u03ac\u03bd\u03bf\u03c5\u03bc\u03b5 \u03ba\u03ac\u03c4\u03b9 \u03c3\u03b1\u03bd:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"typescript\" class=\"language-typescript\">function getLength(thing: typeof Array):number {\n    return thing.length,\n}<\/code><\/pre>\n\n\n\n<p>\u03ba\u03b1\u03b9 \u03b1\u03bd\u03ac\u03bb\u03bf\u03b3\u03b1 \u03bc\u03b5 \u03c4\u03bf \u03c0\u03bb\u03b1\u03af\u03c3\u03b9\u03bf \u03bc\u03c0\u03bf\u03c1\u03b5\u03af \u03bd\u03b1 \u03b5\u03af\u03bd\u03b1\u03b9 \u03c3\u03c9\u03c3\u03c4\u03cc, \u03c3\u03c5\u03bd\u03bf\u03bb\u03b9\u03ba\u03ac \u03b5\u03af\u03bc\u03b1\u03c3\u03c4\u03b5 \u03bb\u03af\u03b3\u03bf \u03b3\u03b5\u03bd\u03b9\u03ba\u03bf\u03af - \u03b8\u03b1 \u03bb\u03b5\u03b9\u03c4\u03bf\u03c5\u03c1\u03b3\u03ae\u03c3\u03b5\u03b9 \u03bc\u03b5 \u03c0\u03af\u03bd\u03b1\u03ba\u03b5\u03c2 \u03c0\u03bf\u03bb\u03bb\u03b1\u03c0\u03bb\u03ce\u03bd \u03c4\u03cd\u03c0\u03c9\u03bd, \u03b1\u03bb\u03bb\u03ac \u03c4\u03b9 \u03b3\u03af\u03bd\u03b5\u03c4\u03b1\u03b9 \u03b1\u03bd \u03b4\u03b5\u03bd \u03be\u03ad\u03c1\u03bf\u03c5\u03bc\u03b5 \u03c0\u03c1\u03b1\u03b3\u03bc\u03b1\u03c4\u03b9\u03ba\u03ac \u03b1\u03bd \u03c4\u03bf \u03c0\u03c1\u03ac\u03b3\u03bc\u03b1 \u03c0\u03c1\u03ad\u03c0\u03b5\u03b9 \u03bd\u03b1 \u03b5\u03af\u03bd\u03b1\u03b9 \u03c0\u03ac\u03bd\u03c4\u03b1 \u03ad\u03bd\u03b1\u03c2 \u03c0\u03af\u03bd\u03b1\u03ba\u03b1\u03c2 - \u03af\u03c3\u03c9\u03c2 \u03c4\u03bf \u03c0\u03c1\u03ac\u03b3\u03bc\u03b1 \u03b5\u03af\u03bd\u03b1\u03b9 \u03ad\u03bd\u03b1 \u03b3\u03ae\u03c0\u03b5\u03b4\u03bf \u03c0\u03bf\u03b4\u03bf\u03c3\u03c6\u03b1\u03af\u03c1\u03bf\u03c5 \u03ae \u03bc\u03b9\u03b1 \u03bc\u03c0\u03b1\u03bd\u03b1\u03bd\u03cc\u03c6\u03bb\u03bf\u03c5\u03b4\u03b1; \u03a3\u03b5 \u03b1\u03c5\u03c4\u03ae \u03c4\u03b7\u03bd \u03c0\u03b5\u03c1\u03af\u03c0\u03c4\u03c9\u03c3\u03b7, \u03c0\u03c1\u03ad\u03c0\u03b5\u03b9 \u03bd\u03b1 \u03c3\u03c5\u03b3\u03ba\u03b5\u03bd\u03c4\u03c1\u03ce\u03c3\u03bf\u03c5\u03bc\u03b5 \u03c4\u03b9\u03c2 \u03ba\u03bf\u03b9\u03bd\u03ad\u03c2 \u03b9\u03b4\u03b9\u03cc\u03c4\u03b7\u03c4\u03b5\u03c2 \u03b1\u03c5\u03c4\u03bf\u03cd \u03c4\u03bf\u03c5 \u03c0\u03c1\u03ac\u03b3\u03bc\u03b1\u03c4\u03bf\u03c2 \u03c3\u03b5 \u03bc\u03b9\u03b1 \u03ba\u03b1\u03c4\u03b1\u03c3\u03ba\u03b5\u03c5\u03ae \u03c0\u03bf\u03c5 \u03bc\u03c0\u03bf\u03c1\u03b5\u03af \u03bd\u03b1 \u03bf\u03c1\u03af\u03c3\u03b5\u03b9 \u03b9\u03b4\u03b9\u03cc\u03c4\u03b7\u03c4\u03b5\u03c2 \u03b5\u03bd\u03cc\u03c2 \u03b1\u03bd\u03c4\u03b9\u03ba\u03b5\u03b9\u03bc\u03ad\u03bd\u03bf\u03c5 - \u03bc\u03b9\u03b1 \u03b4\u03b9\u03b5\u03c0\u03b1\u03c6\u03ae:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"typescript\" class=\"language-typescript\">\u03b4\u03b9\u03b5\u03c0\u03b1\u03c6\u03ae IThingWithLength {\n  length: \u03b1\u03c1\u03b9\u03b8\u03bc\u03cc\u03c2,\n}<\/code><\/pre>\n\n\n\n<p>\u039c\u03c0\u03bf\u03c1\u03bf\u03cd\u03bc\u03b5 \u03bd\u03b1 \u03c7\u03c1\u03b7\u03c3\u03b9\u03bc\u03bf\u03c0\u03bf\u03b9\u03ae\u03c3\u03bf\u03c5\u03bc\u03b5 <code>IThingWithLength<\/code> \u03b4\u03b9\u03b5\u03c0\u03b1\u03c6\u03ae \u03c9\u03c2 \u03c4\u03cd\u03c0\u03bf \u03c4\u03b7\u03c2 <code>\u03c0\u03c1\u03ac\u03b3\u03bc\u03b1<\/code> \u03c0\u03b1\u03c1\u03ac\u03bc\u03b5\u03c4\u03c1\u03bf\u03c2:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"typescript\" class=\"language-typescript\">function getLength(thing: IThingWithLength):number {\n    return thing.length,\n}<\/code><\/pre>\n\n\n\n<p>\u03b5\u03b9\u03bb\u03b9\u03ba\u03c1\u03b9\u03bd\u03ac \u03c3\u03b5 \u03b1\u03c5\u03c4\u03cc \u03c4\u03bf \u03b1\u03c0\u03bb\u03cc \u03c0\u03b1\u03c1\u03ac\u03b4\u03b5\u03b9\u03b3\u03bc\u03b1, \u03b8\u03b1 \u03b5\u03af\u03bd\u03b1\u03b9 \u03b1\u03c0\u03bf\u03bb\u03cd\u03c4\u03c9\u03c2 \u03b5\u03bd\u03c4\u03ac\u03be\u03b5\u03b9, \u03b1\u03bb\u03bb\u03ac \u03b1\u03bd \u03b8\u03ad\u03bb\u03bf\u03c5\u03bc\u03b5 \u03bd\u03b1 \u03ba\u03c1\u03b1\u03c4\u03ae\u03c3\u03bf\u03c5\u03bc\u03b5 \u03b1\u03c5\u03c4\u03cc\u03bd \u03c4\u03bf\u03bd \u03c4\u03cd\u03c0\u03bf \u03b3\u03b5\u03bd\u03b9\u03ba\u03cc, \u03ba\u03b1\u03b9 \u03bd\u03b1 \u03bc\u03b7\u03bd \u03b1\u03bd\u03c4\u03b9\u03bc\u03b5\u03c4\u03c9\u03c0\u03af\u03c3\u03bf\u03c5\u03bc\u03b5 \u03c4\u03bf \u03c0\u03c1\u03cc\u03b2\u03bb\u03b7\u03bc\u03b1 \u03b1\u03c0\u03cc \u03c4\u03bf \u03c0\u03c1\u03ce\u03c4\u03bf \u03c0\u03b1\u03c1\u03ac\u03b4\u03b5\u03b9\u03b3\u03bc\u03b1 \u03bc\u03c0\u03bf\u03c1\u03bf\u03cd\u03bc\u03b5 \u03bd\u03b1 \u03c7\u03c1\u03b7\u03c3\u03b9\u03bc\u03bf\u03c0\u03bf\u03b9\u03ae\u03c3\u03bf\u03c5\u03bc\u03b5 \u03c4\u03bf <strong>\u0393\u03b5\u03bd\u03b9\u03ba\u03bf\u03af \u03c0\u03b5\u03c1\u03b9\u03bf\u03c1\u03b9\u03c3\u03bc\u03bf\u03af<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"typescript\" class=\"language-typescript\">function getLength(thing: T):number {\n    return thing.length,\n}<\/code><\/pre>\n\n\n\n<p>\u03ba\u03b1\u03b9 \u03bd\u03b1 \u03c4\u03bf \u03c7\u03c1\u03b7\u03c3\u03b9\u03bc\u03bf\u03c0\u03bf\u03b9\u03ae\u03c3\u03b5\u03c4\u03b5:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"typescript\" class=\"language-typescript\">\u03b4\u03b9\u03b5\u03c0\u03b1\u03c6\u03ae IBananaPeel {\n  thickness: number,\n  length: number,\n}\n\nconst bananaPeel: IBananaPeel = {thickness: 0.2, length: 3.14},\ngetLength(bananaPeel),<\/code><\/pre>\n\n\n\n<p>\u03a7\u03c1\u03ae\u03c3\u03b7 \u03c4\u03bf\u03c5 <code>\u03b5\u03c0\u03b5\u03ba\u03c4\u03b5\u03af\u03bd\u03b5\u03b9 \u03c4\u03bf<\/code> \u03b5\u03be\u03b1\u03c3\u03c6\u03b1\u03bb\u03af\u03b6\u03b5\u03b9 \u03cc\u03c4\u03b9 <code>T<\/code> \u03b8\u03b1 \u03c0\u03b5\u03c1\u03b9\u03ad\u03c7\u03b5\u03b9 \u03b9\u03b4\u03b9\u03cc\u03c4\u03b7\u03c4\u03b5\u03c2 \u03c0\u03bf\u03c5 \u03bf\u03c1\u03af\u03b6\u03bf\u03bd\u03c4\u03b1\u03b9 \u03b1\u03c0\u03cc <code>IThingWithLength<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u0393\u03b5\u03bd\u03b9\u03ba\u03ad\u03c2 \u03ba\u03bb\u03ac\u03c3\u03b5\u03b9\u03c2<\/h2>\n\n\n\n<p>\u039c\u03ad\u03c7\u03c1\u03b9 \u03b1\u03c5\u03c4\u03cc \u03c4\u03bf \u03c3\u03b7\u03bc\u03b5\u03af\u03bf, \u03b4\u03bf\u03c5\u03bb\u03b5\u03cd\u03b1\u03bc\u03b5 \u03bc\u03b5 \u03b3\u03b5\u03bd\u03b9\u03ba\u03ad\u03c2 \u03c3\u03c5\u03bd\u03b1\u03c1\u03c4\u03ae\u03c3\u03b5\u03b9\u03c2, \u03b1\u03bb\u03bb\u03ac \u03b4\u03b5\u03bd \u03b5\u03af\u03bd\u03b1\u03b9 \u03c4\u03bf \u03bc\u03cc\u03bd\u03bf \u03bc\u03ad\u03c1\u03bf\u03c2 \u03cc\u03c0\u03bf\u03c5 \u03bf\u03b9 \u03b3\u03b5\u03bd\u03b9\u03ba\u03ad\u03c2 \u03bb\u03ac\u03bc\u03c0\u03bf\u03c5\u03bd, \u03b1\u03c2 \u03b4\u03bf\u03cd\u03bc\u03b5 \u03c0\u03ce\u03c2 \u03bc\u03c0\u03bf\u03c1\u03bf\u03cd\u03bc\u03b5 \u03bd\u03b1 \u03c4\u03b9\u03c2 \u03b5\u03bd\u03c3\u03c9\u03bc\u03b1\u03c4\u03ce\u03c3\u03bf\u03c5\u03bc\u03b5 \u03c3\u03b5 \u03ba\u03bb\u03ac\u03c3\u03b5\u03b9\u03c2.<\/p>\n\n\n\n<p>\u03a0\u03c1\u03ce\u03c4\u03b1 \u03b1\u03c0' \u03cc\u03bb\u03b1, \u03b1\u03c2 \u03c0\u03c1\u03bf\u03c3\u03c0\u03b1\u03b8\u03ae\u03c3\u03bf\u03c5\u03bc\u03b5 \u03bd\u03b1 \u03b1\u03c0\u03bf\u03b8\u03b7\u03ba\u03b5\u03cd\u03c3\u03bf\u03c5\u03bc\u03b5 \u03ad\u03bd\u03b1 \u03bc\u03ac\u03c4\u03c3\u03bf \u03bc\u03c0\u03b1\u03bd\u03ac\u03bd\u03b5\u03c2 \u03c3\u03c4\u03bf \u03ba\u03b1\u03bb\u03ac\u03b8\u03b9 \u03bc\u03b5 \u03c4\u03b9\u03c2 \u03bc\u03c0\u03b1\u03bd\u03ac\u03bd\u03b5\u03c2:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"typescript\" class=\"language-typescript\">\u03ba\u03bb\u03ac\u03c3\u03b7 Banana {\n  constructor(\n    public length: number,\n    public color: string,\n    public ionizingRadiation: number\n  ) {}\n}\n\nclass BananaBasket {\n  private bananas: Banana[] = [],\n\n  add(banana: Banana): void {\n    this.bananas.push(banana),\n  }\n}\n\nconst bananaBasket = new BananaBasket(),\nbananaBasket.add(new Banana(3.14, 'red', 10e-7)),<\/code><\/pre>\n\n\n\n<p>\u03a4\u03ce\u03c1\u03b1 \u03b1\u03c2 \u03c0\u03c1\u03bf\u03c3\u03c0\u03b1\u03b8\u03ae\u03c3\u03bf\u03c5\u03bc\u03b5 \u03bd\u03b1 \u03b4\u03b7\u03bc\u03b9\u03bf\u03c5\u03c1\u03b3\u03ae\u03c3\u03bf\u03c5\u03bc\u03b5 \u03ba\u03b1\u03bb\u03ac\u03b8\u03b9 \u03b3\u03b5\u03bd\u03b9\u03ba\u03ae\u03c2 \u03c7\u03c1\u03ae\u03c3\u03b7\u03c2, \u03b3\u03b9\u03b1 \u03b4\u03b9\u03b1\u03c6\u03bf\u03c1\u03b5\u03c4\u03b9\u03ba\u03ac \u03c0\u03c1\u03ac\u03b3\u03bc\u03b1\u03c4\u03b1 \u03bc\u03b5 \u03c4\u03bf\u03bd \u03af\u03b4\u03b9\u03bf \u03c4\u03cd\u03c0\u03bf:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"typescript\" class=\"language-typescript\">class Basket {\n  private stuff: T[] = [];\n\n  add(thing: T): void {\n    this.stuff.push(thing),\n  }\n}\n\nconst bananaBasket = new Basket(),<\/code><\/pre>\n\n\n\n<p>\u039a\u03b1\u03b9 \u03c4\u03ad\u03bb\u03bf\u03c2, \u03b1\u03c2 \u03c5\u03c0\u03bf\u03b8\u03ad\u03c3\u03bf\u03c5\u03bc\u03b5 \u03cc\u03c4\u03b9 \u03c4\u03bf \u03ba\u03b1\u03bb\u03ac\u03b8\u03b9 \u03bc\u03b1\u03c2 \u03b5\u03af\u03bd\u03b1\u03b9 \u03ad\u03bd\u03b1 \u03b4\u03bf\u03c7\u03b5\u03af\u03bf \u03c1\u03b1\u03b4\u03b9\u03b5\u03bd\u03b5\u03c1\u03b3\u03ce\u03bd \u03c5\u03bb\u03b9\u03ba\u03ce\u03bd \u03ba\u03b1\u03b9 \u03cc\u03c4\u03b9 \u03bc\u03c0\u03bf\u03c1\u03bf\u03cd\u03bc\u03b5 \u03bd\u03b1 \u03b1\u03c0\u03bf\u03b8\u03b7\u03ba\u03b5\u03cd\u03c3\u03bf\u03c5\u03bc\u03b5 \u03bc\u03cc\u03bd\u03bf \u03cd\u03bb\u03b7 \u03c0\u03bf\u03c5 \u03ad\u03c7\u03b5\u03b9 <code>\u03b9\u03bf\u03bd\u03af\u03b6\u03bf\u03c5\u03c3\u03b1 \u03b1\u03ba\u03c4\u03b9\u03bd\u03bf\u03b2\u03bf\u03bb\u03af\u03b1<\/code> \u03b9\u03b4\u03b9\u03bf\u03ba\u03c4\u03b7\u03c3\u03af\u03b1:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"typescript\" class=\"language-typescript\">\u03b4\u03b9\u03b1\u03c3\u03cd\u03bd\u03b4\u03b5\u03c3\u03b7 IRadioactive {\n  ionizingRadiation: number,\n}\n\nclass RadioactiveContainer {\n  private stuff: T[] = [];\n\n  add(thing: T): void {\n    this.stuff.push(thing),\n  }\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u0393\u03b5\u03bd\u03b9\u03ba\u03ae \u03b4\u03b9\u03b5\u03c0\u03b1\u03c6\u03ae<\/h2>\n\n\n\n<p>\u03a4\u03ad\u03bb\u03bf\u03c2, \u03b1\u03c2 \u03c0\u03c1\u03bf\u03c3\u03c0\u03b1\u03b8\u03ae\u03c3\u03bf\u03c5\u03bc\u03b5 \u03bd\u03b1 \u03c3\u03c5\u03b3\u03ba\u03b5\u03bd\u03c4\u03c1\u03ce\u03c3\u03bf\u03c5\u03bc\u03b5 \u03cc\u03bb\u03b5\u03c2 \u03c4\u03b9\u03c2 \u03b3\u03bd\u03ce\u03c3\u03b5\u03b9\u03c2 \u03bc\u03b1\u03c2 \u03ba\u03b1\u03b9 \u03bd\u03b1 \u03c7\u03c4\u03af\u03c3\u03bf\u03c5\u03bc\u03b5 \u03bc\u03b9\u03b1 \u03c1\u03b1\u03b4\u03b9\u03b5\u03bd\u03b5\u03c1\u03b3\u03ae \u03b1\u03c5\u03c4\u03bf\u03ba\u03c1\u03b1\u03c4\u03bf\u03c1\u03af\u03b1 \u03c7\u03c1\u03b7\u03c3\u03b9\u03bc\u03bf\u03c0\u03bf\u03b9\u03ce\u03bd\u03c4\u03b1\u03c2 \u03b5\u03c0\u03af\u03c3\u03b7\u03c2 Generic Interfaces:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"typescript\" class=\"language-typescript\">\/\/ \u039a\u03b1\u03b8\u03bf\u03c1\u03b9\u03c3\u03bc\u03cc\u03c2 \u03ba\u03bf\u03b9\u03bd\u03ce\u03bd \u03c7\u03b1\u03c1\u03b1\u03ba\u03c4\u03b7\u03c1\u03b9\u03c3\u03c4\u03b9\u03ba\u03ce\u03bd \u03b3\u03b9\u03b1 \u03c4\u03b1 \u03b4\u03bf\u03c7\u03b5\u03af\u03b1\ninterface IRadioactive {\n  ionizingRadiation: number,\n}\n\n\n\/\/ \u039f\u03c1\u03af\u03b6\u03bf\u03c5\u03bc\u03b5 \u03ba\u03ac\u03c4\u03b9 \u03c0\u03bf\u03c5 \u03b5\u03af\u03bd\u03b1\u03b9 \u03c1\u03b1\u03b4\u03b9\u03b5\u03bd\u03b5\u03c1\u03b3\u03cc\ninterface IBanana extends IRadioactive {\n  length: number,\n  color: string,\n}\n\n\/\/ \u039f\u03c1\u03af\u03c3\u03c4\u03b5 \u03ba\u03ac\u03c4\u03b9 \u03c0\u03bf\u03c5 \u03b4\u03b5\u03bd \u03b5\u03af\u03bd\u03b1\u03b9 \u03c1\u03b1\u03b4\u03b9\u03b5\u03bd\u03b5\u03c1\u03b3\u03cc\ninterface IDog {\n  weight: number,\n}\n\n\/\/ \u039f\u03c1\u03b9\u03c3\u03bc\u03cc\u03c2 \u03b4\u03b9\u03b5\u03c0\u03b1\u03c6\u03ae\u03c2 \u03b3\u03b9\u03b1 \u03b4\u03bf\u03c7\u03b5\u03af\u03bf \u03c0\u03bf\u03c5 \u03bc\u03c0\u03bf\u03c1\u03b5\u03af \u03bd\u03b1 \u03c0\u03b5\u03c1\u03b9\u03ad\u03c7\u03b5\u03b9 \u03bc\u03cc\u03bd\u03bf \u03c1\u03b1\u03b4\u03b9\u03b5\u03bd\u03b5\u03c1\u03b3\u03ac \u03c0\u03c1\u03ac\u03b3\u03bc\u03b1\u03c4\u03b1\ninterface IRadioactiveContainer {\n  add(thing: T): void,\n  getRadioactiveness():number,\n}\n\n\/\/ \u039f\u03c1\u03b9\u03c3\u03bc\u03cc\u03c2 \u03ba\u03bb\u03ac\u03c3\u03b7\u03c2 \u03c0\u03bf\u03c5 \u03c5\u03bb\u03bf\u03c0\u03bf\u03b9\u03b5\u03af \u03c4\u03b7 \u03b4\u03b9\u03b5\u03c0\u03b1\u03c6\u03ae radioactive container\nclass RadioactiveContainer implements IRadioactiveContainer {\n  private stuff: T[] = [];\n\n  add(thing: T): void {\n    this.stuff.push(thing),\n  }\n\n  getRadioactiveness(): number {\n      return this.stuff.reduce((a, b) =&gt; a + b.ionizingRadiation, 0)\n  }\n}\n\n\/\/ ERROR! \u039f \u03c4\u03cd\u03c0\u03bf\u03c2 'IDog' \u03b4\u03b5\u03bd \u03b9\u03ba\u03b1\u03bd\u03bf\u03c0\u03bf\u03b9\u03b5\u03af \u03c4\u03bf\u03bd \u03c0\u03b5\u03c1\u03b9\u03bf\u03c1\u03b9\u03c3\u03bc\u03cc 'IRadioactive'\n\/\/ \u039a\u03b1\u03b9 \u03b5\u03af\u03bd\u03b1\u03b9 \u03ba\u03ac\u03c0\u03c9\u03c2 \u03b2\u03ac\u03bd\u03b1\u03c5\u03c3\u03bf \u03bd\u03b1 \u03b1\u03c0\u03bf\u03b8\u03b7\u03ba\u03b5\u03cd\u03bf\u03c5\u03bc\u03b5 \u03c3\u03ba\u03cd\u03bb\u03bf\u03c5\u03c2 \u03bc\u03ad\u03c3\u03b1 \u03c3\u03b5 \u03c1\u03b1\u03b4\u03b9\u03b5\u03bd\u03b5\u03c1\u03b3\u03cc \u03b4\u03bf\u03c7\u03b5\u03af\u03bf\nconst dogsContainer = new RadioactiveContainer(),\n\n\/\/ All good fam!\nconst radioactiveContainer = new RadioactiveContainer(),\n\n\/\/ \u0398\u03c5\u03bc\u03b7\u03b8\u03b5\u03af\u03c4\u03b5 \u03bd\u03b1 \u03c4\u03b1\u03be\u03b9\u03bd\u03bf\u03bc\u03ae\u03c3\u03b5\u03c4\u03b5 \u03c4\u03b1 \u03c1\u03b1\u03b4\u03b9\u03b5\u03bd\u03b5\u03c1\u03b3\u03ac \u03c3\u03b1\u03c2 \u03b1\u03c0\u03cc\u03b2\u03bb\u03b7\u03c4\u03b1 - \u03b4\u03b7\u03bc\u03b9\u03bf\u03c5\u03c1\u03b3\u03ae\u03c3\u03c4\u03b5 \u03be\u03b5\u03c7\u03c9\u03c1\u03b9\u03c3\u03c4\u03cc \u03ba\u03ac\u03b4\u03bf \u03bc\u03cc\u03bd\u03bf \u03b3\u03b9\u03b1 \u03c4\u03b9\u03c2 \u03bc\u03c0\u03b1\u03bd\u03ac\u03bd\u03b5\u03c2\nconst bananasContainer = new RadioactiveContainer(),<\/code><\/pre>\n\n\n\n<p>\u0391\u03c5\u03c4\u03cc \u03b5\u03af\u03bd\u03b1\u03b9 \u03cc\u03bb\u03bf, \u03c0\u03b1\u03b9\u03b4\u03b9\u03ac!<\/p>","protected":false},"excerpt":{"rendered":"<p>\u03a4\u03b1 generics \u03c0\u03b1\u03c1\u03ad\u03c7\u03bf\u03c5\u03bd \u03b5\u03c0\u03b1\u03bd\u03b1\u03c7\u03c1\u03b7\u03c3\u03b9\u03bc\u03bf\u03c0\u03bf\u03b9\u03ae\u03c3\u03b9\u03bc\u03b1 \u03ba\u03bf\u03bc\u03bc\u03ac\u03c4\u03b9\u03b1 \u03ba\u03ce\u03b4\u03b9\u03ba\u03b1 \u03c0\u03bf\u03c5 \u03bb\u03b5\u03b9\u03c4\u03bf\u03c5\u03c1\u03b3\u03bf\u03cd\u03bd \u03bc\u03b5 \u03ad\u03bd\u03b1\u03bd \u03b1\u03c1\u03b9\u03b8\u03bc\u03cc \u03c4\u03cd\u03c0\u03c9\u03bd \u03b1\u03bd\u03c4\u03af \u03b3\u03b9\u03b1 \u03ad\u03bd\u03b1\u03bd \u03c4\u03cd\u03c0\u03bf. \u03a4\u03b1 generics \u03c0\u03b1\u03c1\u03ad\u03c7\u03bf\u03c5\u03bd \u03ad\u03bd\u03b1\u03bd \u03c4\u03c1\u03cc\u03c0\u03bf \u03bd\u03b1 \u03b1\u03bd\u03c4\u03b9\u03bc\u03b5\u03c4\u03c9\u03c0\u03af\u03b6\u03b5\u03c4\u03b5 \u03c4\u03bf\u03bd \u03c4\u03cd\u03c0\u03bf \u03c9\u03c2 \u03bc\u03b5\u03c4\u03b1\u03b2\u03bb\u03b7\u03c4\u03ae \u03ba\u03b1\u03b9 \u03bd\u03b1 \u03c4\u03bf\u03bd \u03c0\u03c1\u03bf\u03c3\u03b4\u03b9\u03bf\u03c1\u03af\u03b6\u03b5\u03c4\u03b5 \u03ba\u03b1\u03c4\u03ac \u03c4\u03b7 \u03c7\u03c1\u03ae\u03c3\u03b7, \u03c0\u03b1\u03c1\u03cc\u03bc\u03bf\u03b9\u03b1 \u03bc\u03b5 \u03c4\u03b9\u03c2 \u03c0\u03b1\u03c1\u03b1\u03bc\u03ad\u03c4\u03c1\u03bf\u03c5\u03c2 \u03c3\u03c5\u03bd\u03b1\u03c1\u03c4\u03ae\u03c3\u03b5\u03c9\u03bd.<\/p>","protected":false},"author":2,"featured_media":3249,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[8],"tags":[],"class_list":["post-3248","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software-development"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Generics in TypeScript - The Codest<\/title>\n<meta name=\"description\" content=\"Generics provide reusable bits of code that work with a number of types instead of a single type. Generics provide a way to treat type as a variable and specify it on usage, similar to function parameters.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/thecodest.co\/el\/blog\/\u03b3\u03b5\u03bd\u03b9\u03ba\u03ad\u03c2-\u03c3\u03b5-typescript\/\" \/>\n<meta property=\"og:locale\" content=\"el_GR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Generics in TypeScript\" \/>\n<meta property=\"og:description\" content=\"Generics provide reusable bits of code that work with a number of types instead of a single type. Generics provide a way to treat type as a variable and specify it on usage, similar to function parameters.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/thecodest.co\/el\/blog\/\u03b3\u03b5\u03bd\u03b9\u03ba\u03ad\u03c2-\u03c3\u03b5-typescript\/\" \/>\n<meta property=\"og:site_name\" content=\"The Codest\" \/>\n<meta property=\"article:published_time\" content=\"2020-07-13T08:52:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-04-24T11:39:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/thecodest.co\/app\/uploads\/2024\/05\/cover-image-75.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"600\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"thecodest\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"thecodest\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u03bb\u03b5\u03c0\u03c4\u03ac\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/thecodest.co\\\/blog\\\/generics-in-typescript\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/thecodest.co\\\/blog\\\/generics-in-typescript\\\/\"},\"author\":{\"name\":\"thecodest\",\"@id\":\"https:\\\/\\\/thecodest.co\\\/#\\\/schema\\\/person\\\/7e3fe41dfa4f4e41a7baad4c6e0d4f76\"},\"headline\":\"Generics in TypeScript\",\"datePublished\":\"2020-07-13T08:52:00+00:00\",\"dateModified\":\"2026-04-24T11:39:03+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/thecodest.co\\\/blog\\\/generics-in-typescript\\\/\"},\"wordCount\":516,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/thecodest.co\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/thecodest.co\\\/blog\\\/generics-in-typescript\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/thecodest.co\\\/app\\\/uploads\\\/2024\\\/05\\\/cover-image-75.jpg\",\"articleSection\":[\"Software Development\"],\"inLanguage\":\"el\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/thecodest.co\\\/blog\\\/generics-in-typescript\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/thecodest.co\\\/blog\\\/generics-in-typescript\\\/\",\"url\":\"https:\\\/\\\/thecodest.co\\\/blog\\\/generics-in-typescript\\\/\",\"name\":\"Generics in TypeScript - The Codest\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/thecodest.co\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/thecodest.co\\\/blog\\\/generics-in-typescript\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/thecodest.co\\\/blog\\\/generics-in-typescript\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/thecodest.co\\\/app\\\/uploads\\\/2024\\\/05\\\/cover-image-75.jpg\",\"datePublished\":\"2020-07-13T08:52:00+00:00\",\"dateModified\":\"2026-04-24T11:39:03+00:00\",\"description\":\"Generics provide reusable bits of code that work with a number of types instead of a single type. Generics provide a way to treat type as a variable and specify it on usage, similar to function parameters.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/thecodest.co\\\/blog\\\/generics-in-typescript\\\/#breadcrumb\"},\"inLanguage\":\"el\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/thecodest.co\\\/blog\\\/generics-in-typescript\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"el\",\"@id\":\"https:\\\/\\\/thecodest.co\\\/blog\\\/generics-in-typescript\\\/#primaryimage\",\"url\":\"https:\\\/\\\/thecodest.co\\\/app\\\/uploads\\\/2024\\\/05\\\/cover-image-75.jpg\",\"contentUrl\":\"https:\\\/\\\/thecodest.co\\\/app\\\/uploads\\\/2024\\\/05\\\/cover-image-75.jpg\",\"width\":1200,\"height\":600},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/thecodest.co\\\/blog\\\/generics-in-typescript\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/thecodest.co\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Generics in TypeScript\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/thecodest.co\\\/#website\",\"url\":\"https:\\\/\\\/thecodest.co\\\/\",\"name\":\"The Codest\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/thecodest.co\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/thecodest.co\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"el\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/thecodest.co\\\/#organization\",\"name\":\"The Codest\",\"url\":\"https:\\\/\\\/thecodest.co\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"el\",\"@id\":\"https:\\\/\\\/thecodest.co\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/thecodest.co\\\/app\\\/uploads\\\/2024\\\/03\\\/thecodest-logo.svg\",\"contentUrl\":\"https:\\\/\\\/thecodest.co\\\/app\\\/uploads\\\/2024\\\/03\\\/thecodest-logo.svg\",\"width\":144,\"height\":36,\"caption\":\"The Codest\"},\"image\":{\"@id\":\"https:\\\/\\\/thecodest.co\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/pl.linkedin.com\\\/company\\\/codest\",\"https:\\\/\\\/clutch.co\\\/profile\\\/codest\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/thecodest.co\\\/#\\\/schema\\\/person\\\/7e3fe41dfa4f4e41a7baad4c6e0d4f76\",\"name\":\"thecodest\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"el\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5dbfe6a1e8c86e432e8812759e34e6fe82ebac75119ae3237a6c1311fa19caf4?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5dbfe6a1e8c86e432e8812759e34e6fe82ebac75119ae3237a6c1311fa19caf4?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5dbfe6a1e8c86e432e8812759e34e6fe82ebac75119ae3237a6c1311fa19caf4?s=96&d=mm&r=g\",\"caption\":\"thecodest\"},\"url\":\"https:\\\/\\\/thecodest.co\\\/el\\\/author\\\/thecodest\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"\u0393\u03b5\u03bd\u03cc\u03c3\u03b7\u03bc\u03b1 \u03c3\u03b5 TypeScript - The Codest","description":"\u03a4\u03b1 generics \u03c0\u03b1\u03c1\u03ad\u03c7\u03bf\u03c5\u03bd \u03b5\u03c0\u03b1\u03bd\u03b1\u03c7\u03c1\u03b7\u03c3\u03b9\u03bc\u03bf\u03c0\u03bf\u03b9\u03ae\u03c3\u03b9\u03bc\u03b1 \u03ba\u03bf\u03bc\u03bc\u03ac\u03c4\u03b9\u03b1 \u03ba\u03ce\u03b4\u03b9\u03ba\u03b1 \u03c0\u03bf\u03c5 \u03bb\u03b5\u03b9\u03c4\u03bf\u03c5\u03c1\u03b3\u03bf\u03cd\u03bd \u03bc\u03b5 \u03ad\u03bd\u03b1\u03bd \u03b1\u03c1\u03b9\u03b8\u03bc\u03cc \u03c4\u03cd\u03c0\u03c9\u03bd \u03b1\u03bd\u03c4\u03af \u03b3\u03b9\u03b1 \u03ad\u03bd\u03b1\u03bd \u03c4\u03cd\u03c0\u03bf. \u03a4\u03b1 generics \u03c0\u03b1\u03c1\u03ad\u03c7\u03bf\u03c5\u03bd \u03ad\u03bd\u03b1\u03bd \u03c4\u03c1\u03cc\u03c0\u03bf \u03bd\u03b1 \u03b1\u03bd\u03c4\u03b9\u03bc\u03b5\u03c4\u03c9\u03c0\u03af\u03b6\u03b5\u03c4\u03b5 \u03c4\u03bf\u03bd \u03c4\u03cd\u03c0\u03bf \u03c9\u03c2 \u03bc\u03b5\u03c4\u03b1\u03b2\u03bb\u03b7\u03c4\u03ae \u03ba\u03b1\u03b9 \u03bd\u03b1 \u03c4\u03bf\u03bd \u03c0\u03c1\u03bf\u03c3\u03b4\u03b9\u03bf\u03c1\u03af\u03b6\u03b5\u03c4\u03b5 \u03ba\u03b1\u03c4\u03ac \u03c4\u03b7 \u03c7\u03c1\u03ae\u03c3\u03b7, \u03c0\u03b1\u03c1\u03cc\u03bc\u03bf\u03b9\u03b1 \u03bc\u03b5 \u03c4\u03b9\u03c2 \u03c0\u03b1\u03c1\u03b1\u03bc\u03ad\u03c4\u03c1\u03bf\u03c5\u03c2 \u03c3\u03c5\u03bd\u03b1\u03c1\u03c4\u03ae\u03c3\u03b5\u03c9\u03bd.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/thecodest.co\/el\/blog\/\u03b3\u03b5\u03bd\u03b9\u03ba\u03ad\u03c2-\u03c3\u03b5-typescript\/","og_locale":"el_GR","og_type":"article","og_title":"Generics in TypeScript","og_description":"Generics provide reusable bits of code that work with a number of types instead of a single type. Generics provide a way to treat type as a variable and specify it on usage, similar to function parameters.","og_url":"https:\/\/thecodest.co\/el\/blog\/\u03b3\u03b5\u03bd\u03b9\u03ba\u03ad\u03c2-\u03c3\u03b5-typescript\/","og_site_name":"The Codest","article_published_time":"2020-07-13T08:52:00+00:00","article_modified_time":"2026-04-24T11:39:03+00:00","og_image":[{"width":1200,"height":600,"url":"https:\/\/thecodest.co\/app\/uploads\/2024\/05\/cover-image-75.jpg","type":"image\/jpeg"}],"author":"thecodest","twitter_card":"summary_large_image","twitter_misc":{"Written by":"thecodest","Est. reading time":"3 \u03bb\u03b5\u03c0\u03c4\u03ac"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/thecodest.co\/blog\/generics-in-typescript\/#article","isPartOf":{"@id":"https:\/\/thecodest.co\/blog\/generics-in-typescript\/"},"author":{"name":"thecodest","@id":"https:\/\/thecodest.co\/#\/schema\/person\/7e3fe41dfa4f4e41a7baad4c6e0d4f76"},"headline":"Generics in TypeScript","datePublished":"2020-07-13T08:52:00+00:00","dateModified":"2026-04-24T11:39:03+00:00","mainEntityOfPage":{"@id":"https:\/\/thecodest.co\/blog\/generics-in-typescript\/"},"wordCount":516,"commentCount":0,"publisher":{"@id":"https:\/\/thecodest.co\/#organization"},"image":{"@id":"https:\/\/thecodest.co\/blog\/generics-in-typescript\/#primaryimage"},"thumbnailUrl":"https:\/\/thecodest.co\/app\/uploads\/2024\/05\/cover-image-75.jpg","articleSection":["Software Development"],"inLanguage":"el","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/thecodest.co\/blog\/generics-in-typescript\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/thecodest.co\/blog\/generics-in-typescript\/","url":"https:\/\/thecodest.co\/blog\/generics-in-typescript\/","name":"\u0393\u03b5\u03bd\u03cc\u03c3\u03b7\u03bc\u03b1 \u03c3\u03b5 TypeScript - The Codest","isPartOf":{"@id":"https:\/\/thecodest.co\/#website"},"primaryImageOfPage":{"@id":"https:\/\/thecodest.co\/blog\/generics-in-typescript\/#primaryimage"},"image":{"@id":"https:\/\/thecodest.co\/blog\/generics-in-typescript\/#primaryimage"},"thumbnailUrl":"https:\/\/thecodest.co\/app\/uploads\/2024\/05\/cover-image-75.jpg","datePublished":"2020-07-13T08:52:00+00:00","dateModified":"2026-04-24T11:39:03+00:00","description":"\u03a4\u03b1 generics \u03c0\u03b1\u03c1\u03ad\u03c7\u03bf\u03c5\u03bd \u03b5\u03c0\u03b1\u03bd\u03b1\u03c7\u03c1\u03b7\u03c3\u03b9\u03bc\u03bf\u03c0\u03bf\u03b9\u03ae\u03c3\u03b9\u03bc\u03b1 \u03ba\u03bf\u03bc\u03bc\u03ac\u03c4\u03b9\u03b1 \u03ba\u03ce\u03b4\u03b9\u03ba\u03b1 \u03c0\u03bf\u03c5 \u03bb\u03b5\u03b9\u03c4\u03bf\u03c5\u03c1\u03b3\u03bf\u03cd\u03bd \u03bc\u03b5 \u03ad\u03bd\u03b1\u03bd \u03b1\u03c1\u03b9\u03b8\u03bc\u03cc \u03c4\u03cd\u03c0\u03c9\u03bd \u03b1\u03bd\u03c4\u03af \u03b3\u03b9\u03b1 \u03ad\u03bd\u03b1\u03bd \u03c4\u03cd\u03c0\u03bf. \u03a4\u03b1 generics \u03c0\u03b1\u03c1\u03ad\u03c7\u03bf\u03c5\u03bd \u03ad\u03bd\u03b1\u03bd \u03c4\u03c1\u03cc\u03c0\u03bf \u03bd\u03b1 \u03b1\u03bd\u03c4\u03b9\u03bc\u03b5\u03c4\u03c9\u03c0\u03af\u03b6\u03b5\u03c4\u03b5 \u03c4\u03bf\u03bd \u03c4\u03cd\u03c0\u03bf \u03c9\u03c2 \u03bc\u03b5\u03c4\u03b1\u03b2\u03bb\u03b7\u03c4\u03ae \u03ba\u03b1\u03b9 \u03bd\u03b1 \u03c4\u03bf\u03bd \u03c0\u03c1\u03bf\u03c3\u03b4\u03b9\u03bf\u03c1\u03af\u03b6\u03b5\u03c4\u03b5 \u03ba\u03b1\u03c4\u03ac \u03c4\u03b7 \u03c7\u03c1\u03ae\u03c3\u03b7, \u03c0\u03b1\u03c1\u03cc\u03bc\u03bf\u03b9\u03b1 \u03bc\u03b5 \u03c4\u03b9\u03c2 \u03c0\u03b1\u03c1\u03b1\u03bc\u03ad\u03c4\u03c1\u03bf\u03c5\u03c2 \u03c3\u03c5\u03bd\u03b1\u03c1\u03c4\u03ae\u03c3\u03b5\u03c9\u03bd.","breadcrumb":{"@id":"https:\/\/thecodest.co\/blog\/generics-in-typescript\/#breadcrumb"},"inLanguage":"el","potentialAction":[{"@type":"ReadAction","target":["https:\/\/thecodest.co\/blog\/generics-in-typescript\/"]}]},{"@type":"ImageObject","inLanguage":"el","@id":"https:\/\/thecodest.co\/blog\/generics-in-typescript\/#primaryimage","url":"https:\/\/thecodest.co\/app\/uploads\/2024\/05\/cover-image-75.jpg","contentUrl":"https:\/\/thecodest.co\/app\/uploads\/2024\/05\/cover-image-75.jpg","width":1200,"height":600},{"@type":"BreadcrumbList","@id":"https:\/\/thecodest.co\/blog\/generics-in-typescript\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/thecodest.co\/"},{"@type":"ListItem","position":2,"name":"Generics in TypeScript"}]},{"@type":"WebSite","@id":"https:\/\/thecodest.co\/#website","url":"https:\/\/thecodest.co\/","name":"The Codest","description":"","publisher":{"@id":"https:\/\/thecodest.co\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/thecodest.co\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"el"},{"@type":"Organization","@id":"https:\/\/thecodest.co\/#organization","name":"The Codest","url":"https:\/\/thecodest.co\/","logo":{"@type":"ImageObject","inLanguage":"el","@id":"https:\/\/thecodest.co\/#\/schema\/logo\/image\/","url":"https:\/\/thecodest.co\/app\/uploads\/2024\/03\/thecodest-logo.svg","contentUrl":"https:\/\/thecodest.co\/app\/uploads\/2024\/03\/thecodest-logo.svg","width":144,"height":36,"caption":"The Codest"},"image":{"@id":"https:\/\/thecodest.co\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/pl.linkedin.com\/company\/codest","https:\/\/clutch.co\/profile\/codest"]},{"@type":"Person","@id":"https:\/\/thecodest.co\/#\/schema\/person\/7e3fe41dfa4f4e41a7baad4c6e0d4f76","name":"thecodest","image":{"@type":"ImageObject","inLanguage":"el","@id":"https:\/\/secure.gravatar.com\/avatar\/5dbfe6a1e8c86e432e8812759e34e6fe82ebac75119ae3237a6c1311fa19caf4?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/5dbfe6a1e8c86e432e8812759e34e6fe82ebac75119ae3237a6c1311fa19caf4?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5dbfe6a1e8c86e432e8812759e34e6fe82ebac75119ae3237a6c1311fa19caf4?s=96&d=mm&r=g","caption":"thecodest"},"url":"https:\/\/thecodest.co\/el\/author\/thecodest\/"}]}},"_links":{"self":[{"href":"https:\/\/thecodest.co\/el\/wp-json\/wp\/v2\/posts\/3248","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thecodest.co\/el\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thecodest.co\/el\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thecodest.co\/el\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/thecodest.co\/el\/wp-json\/wp\/v2\/comments?post=3248"}],"version-history":[{"count":9,"href":"https:\/\/thecodest.co\/el\/wp-json\/wp\/v2\/posts\/3248\/revisions"}],"predecessor-version":[{"id":7822,"href":"https:\/\/thecodest.co\/el\/wp-json\/wp\/v2\/posts\/3248\/revisions\/7822"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/thecodest.co\/el\/wp-json\/wp\/v2\/media\/3249"}],"wp:attachment":[{"href":"https:\/\/thecodest.co\/el\/wp-json\/wp\/v2\/media?parent=3248"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thecodest.co\/el\/wp-json\/wp\/v2\/categories?post=3248"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thecodest.co\/el\/wp-json\/wp\/v2\/tags?post=3248"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}