{"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":"genericos-em-typescript","status":"publish","type":"post","link":"https:\/\/thecodest.co\/pt\/blog\/generics-in-typescript\/","title":{"rendered":"Gen\u00e9ricos em TypeScript"},"content":{"rendered":"<p>Os gen\u00e9ricos podem ser utilizados em conjunto com fun\u00e7\u00f5es (criando uma fun\u00e7\u00e3o gen\u00e9rica), classes (criando uma classe gen\u00e9rica) e interfaces (criando uma interface gen\u00e9rica).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Utiliza\u00e7\u00e3o b\u00e1sica<\/h2>\n\n\n\n<p>Provavelmente j\u00e1 utilizou gen\u00e9ricos no passado, mesmo sem o saber - a utiliza\u00e7\u00e3o mais comum dos gen\u00e9ricos \u00e9 declarar uma matriz:<\/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>N\u00e3o \u00e9 muito especial \u00e0 primeira vista, apenas declaramos <code>minhaVariedade<\/code> como um array de strings, mas \u00e9 o mesmo que uma declara\u00e7\u00e3o gen\u00e9rica:<\/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\">Manter as coisas expl\u00edcitas<\/h2>\n\n\n\n<p>Comecemos com um exemplo muito simples - como \u00e9 que poder\u00edamos transferir esta baunilha <a href=\"https:\/\/thecodest.co\/pt\/blog\/hire-vue-js-developers\/\">JS<\/a> fun\u00e7\u00e3o para <a href=\"https:\/\/thecodest.co\/pt\/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>Esta fun\u00e7\u00e3o devolver\u00e1 uma matriz preenchida com uma determinada quantidade de <code>enchimento<\/code>, portanto <code>comprimento<\/code> ser\u00e1 <code>n\u00famero<\/code> e toda a fun\u00e7\u00e3o devolver\u00e1 uma matriz de <code>enchimento<\/code> - mas o que \u00e9 um enchimento? Nesta altura, pode ser qualquer coisa, por isso uma op\u00e7\u00e3o \u00e9 utilizar <code>qualquer<\/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>Utilizar <code>qualquer<\/code> \u00e9 certamente gen\u00e9rico - podemos passar literalmente qualquer coisa, por isso \"trabalhar com um n\u00famero de tipos em vez de um \u00fanico tipo\" da defini\u00e7\u00e3o est\u00e1 totalmente coberto, mas perdemos a liga\u00e7\u00e3o entre <code>enchimento<\/code> e o tipo de retorno. Neste caso, queremos devolver uma coisa comum, e podemos definir explicitamente esta coisa comum como <strong>par\u00e2metro de tipo<\/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>e utilizar desta forma:<\/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\">Restri\u00e7\u00f5es gen\u00e9ricas<\/h2>\n\n\n\n<p>Vejamos outros casos, provavelmente mais comuns. Porque \u00e9 que usamos tipos em fun\u00e7\u00f5es? Para mim, \u00e9 para garantir que os argumentos passados para a fun\u00e7\u00e3o t\u00eam algumas propriedades com as quais quero interagir.<\/p>\n\n\n\n<p>Mais uma vez vamos tentar portar uma fun\u00e7\u00e3o simples do JS para o 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>Temos um enigma n\u00e3o trivial - como garantir que a coisa tem um <code>comprimento<\/code> e o primeiro pensamento pode ser fazer algo do g\u00e9nero:<\/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>e, dependendo do contexto, pode estar correto, mas em geral somos um pouco gen\u00e9ricos - funciona com matrizes de v\u00e1rios tipos, mas e se n\u00e3o soubermos se a coisa deve ser sempre uma matriz - talvez a coisa seja um campo de futebol ou uma casca de banana? Neste caso, temos de reunir as propriedades comuns dessa coisa numa constru\u00e7\u00e3o que possa definir as propriedades de um objeto - uma interface:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"typescript\" class=\"language-typescript\">interface IThingWithLength {\n  comprimento: n\u00famero;\n}<\/code><\/pre>\n\n\n\n<p>Podemos utilizar <code>IThingWithLength<\/code> como tipo da interface <code>coisa<\/code> par\u00e2metro:<\/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>francamente, neste exemplo simples, n\u00e3o haver\u00e1 problema algum, mas se quisermos manter este tipo gen\u00e9rico e n\u00e3o enfrentar o problema do primeiro exemplo, podemos usar <strong>Restri\u00e7\u00f5es gen\u00e9ricas<\/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>e utiliz\u00e1-lo:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"typescript\" class=\"language-typescript\">interface IBananaPeel {\n  espessura: n\u00famero;\n  comprimento: n\u00famero;\n}\n\nconst bananaPeel: IBananaPeel = {thickness: 0.2, length: 3.14};\ngetLength(bananaPeel);<\/code><\/pre>\n\n\n\n<p>Utilizar <code>estende-se<\/code> garante que <code>T<\/code> conter\u00e1 propriedades que s\u00e3o definidas por <code>IThingWithLength<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Classes gen\u00e9ricas<\/h2>\n\n\n\n<p>At\u00e9 agora, est\u00e1vamos a trabalhar com fun\u00e7\u00f5es gen\u00e9ricas, mas n\u00e3o \u00e9 o \u00fanico s\u00edtio onde os gen\u00e9ricos brilham, vamos ver como os podemos incorporar nas classes.<\/p>\n\n\n\n<p>Em primeiro lugar, vamos tentar guardar um cacho de bananas no cesto das bananas:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"typescript\" class=\"language-typescript\">classe Banana {\n  construtor(\n    public comprimento: n\u00famero,\n    public cor: 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>Agora vamos tentar criar um cesto de uso geral, para coisas diferentes com o mesmo tipo:<\/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>E, por \u00faltimo, vamos supor que o nosso cesto \u00e9 um contentor de material radioativo e que s\u00f3 podemos armazenar mat\u00e9ria que tenha <code>radia\u00e7\u00e3o ionizante<\/code> propriedade:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"typescript\" class=\"language-typescript\">interface IRadioactiva {\n  ionizingRadiation: n\u00famero;\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\">Interface gen\u00e9rica<\/h2>\n\n\n\n<p>Por fim, vamos tentar reunir todos os nossos conhecimentos e construir um imp\u00e9rio radioativo utilizando tamb\u00e9m Interfaces Gen\u00e9ricas:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"typescript\" class=\"language-typescript\">\/\/ Definir atributos comuns para os contentores\ninterface IRadioactive {\n  ionizingRadiation: number;\n}\n\n\n\/\/ Definir algo que \u00e9 radioativo\ninterface IBanana extends IRadioactive {\n  comprimento: n\u00famero;\n  cor: string;\n}\n\n\/\/ Definir algo que n\u00e3o \u00e9 radioativo\ninterface IDog {\n  peso: n\u00famero;\n}\n\n\/\/ Definir interface para um contentor que s\u00f3 pode conter coisas radioactivas\ninterface IRadioactiveContainer {\n  add(thing: T): void;\n  getRadioactiveness():number;\n}\n\n\/\/ Definir a classe que implementa a interface do contentor radioativo\nclass RadioactiveContainer implements IRadioactiveContainer {\n  private stuff: T[] = [];\n\n  add(thing: T): void {\n    this.stuff.push(thing);\n  }\n\n  getRadioactiveness(): n\u00famero {\n      return this.stuff.reduce((a, b) =&gt; a + b.ionizingRadiation, 0)\n  }\n}\n\n\/\/ ERRO! O tipo 'IDog' n\u00e3o satisfaz a restri\u00e7\u00e3o 'IRadioactive'\n\/\/ E \u00e9 um pouco brutal guardar c\u00e3es dentro de um contentor radioativo\nconst dogsContainer = new RadioactiveContainer();\n\n\/\/ Tudo bem, amigo!\nconst radioactiveContainer = new RadioactiveContainer();\n\n\/\/ Lembra-te de separar os teus res\u00edduos radioactivos - cria um contentor separado s\u00f3 para bananas\nconst bananasContainer = new RadioactiveContainer();<\/code><\/pre>\n\n\n\n<p>\u00c9 tudo, pessoal!<\/p>","protected":false},"excerpt":{"rendered":"<p>Os gen\u00e9ricos fornecem partes reutiliz\u00e1veis de c\u00f3digo que funcionam com v\u00e1rios tipos em vez de um \u00fanico tipo. Os gen\u00e9ricos permitem tratar o tipo como uma vari\u00e1vel e especific\u00e1-lo aquando da sua utiliza\u00e7\u00e3o, \u00e0 semelhan\u00e7a dos par\u00e2metros das fun\u00e7\u00f5es.<\/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=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/thecodest.co\/pt\/blogue\/genericos-em-typescript\/\" \/>\n<meta property=\"og:locale\" content=\"pt_PT\" \/>\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\/pt\/blogue\/genericos-em-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 minutos\" \/>\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\":\"pt-PT\",\"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\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/thecodest.co\\\/blog\\\/generics-in-typescript\\\/#breadcrumb\"},\"inLanguage\":\"pt-PT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/thecodest.co\\\/blog\\\/generics-in-typescript\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-PT\",\"@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\":\"pt-PT\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/thecodest.co\\\/#organization\",\"name\":\"The Codest\",\"url\":\"https:\\\/\\\/thecodest.co\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-PT\",\"@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\":\"pt-PT\",\"@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\\\/pt\\\/author\\\/thecodest\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Gen\u00e9ricos em TypeScript - The Codest","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\/pt\/blogue\/genericos-em-typescript\/","og_locale":"pt_PT","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\/pt\/blogue\/genericos-em-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 minutos"},"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":"pt-PT","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":"Gen\u00e9ricos em 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","breadcrumb":{"@id":"https:\/\/thecodest.co\/blog\/generics-in-typescript\/#breadcrumb"},"inLanguage":"pt-PT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/thecodest.co\/blog\/generics-in-typescript\/"]}]},{"@type":"ImageObject","inLanguage":"pt-PT","@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":"pt-PT"},{"@type":"Organization","@id":"https:\/\/thecodest.co\/#organization","name":"The Codest","url":"https:\/\/thecodest.co\/","logo":{"@type":"ImageObject","inLanguage":"pt-PT","@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":"pt-PT","@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\/pt\/author\/thecodest\/"}]}},"_links":{"self":[{"href":"https:\/\/thecodest.co\/pt\/wp-json\/wp\/v2\/posts\/3248","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thecodest.co\/pt\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thecodest.co\/pt\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thecodest.co\/pt\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/thecodest.co\/pt\/wp-json\/wp\/v2\/comments?post=3248"}],"version-history":[{"count":9,"href":"https:\/\/thecodest.co\/pt\/wp-json\/wp\/v2\/posts\/3248\/revisions"}],"predecessor-version":[{"id":7822,"href":"https:\/\/thecodest.co\/pt\/wp-json\/wp\/v2\/posts\/3248\/revisions\/7822"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/thecodest.co\/pt\/wp-json\/wp\/v2\/media\/3249"}],"wp:attachment":[{"href":"https:\/\/thecodest.co\/pt\/wp-json\/wp\/v2\/media?parent=3248"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thecodest.co\/pt\/wp-json\/wp\/v2\/categories?post=3248"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thecodest.co\/pt\/wp-json\/wp\/v2\/tags?post=3248"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}