Zum Hauptinhalt springen
Echtzeit-Radar & Feeds
Alle RSS Feeds ➔
👥 Community & Social
Windows Tipps & SecurityAnnouncing new builds for 2 October 2026(02.10.2026 um 19:04 Uhr)
•••
Sicherheitslücken (CVE)Hardening a Self-Managed GitLab Instance After CVE-2026-85706(02.10.2026 um 19:20 Uhr)
•
Sichere ProgrammierungA Local Voice Accountability Partner for Task Paralysis(02.10.2026 um 19:20 Uhr)
•
Sichere ProgrammierungRemote MCP tools that run long: what your agent actually gets back(02.10.2026 um 19:22 Uhr)
•
Sichere ProgrammierungYour EA crashed at 3am — who hits the brake?(02.10.2026 um 19:22 Uhr)
••••
Windows Tipps & SecurityAnnouncing new builds for 2 October 2026(02.10.2026 um 19:04 Uhr)
•••
Sicherheitslücken (CVE)Hardening a Self-Managed GitLab Instance After CVE-2026-85706(02.10.2026 um 19:20 Uhr)
•
Sichere ProgrammierungA Local Voice Accountability Partner for Task Paralysis(02.10.2026 um 19:20 Uhr)
•
Sichere ProgrammierungRemote MCP tools that run long: what your agent actually gets back(02.10.2026 um 19:22 Uhr)
•
Sichere ProgrammierungYour EA crashed at 3am — who hits the brake?(02.10.2026 um 19:22 Uhr)
••••
Intelligence View
⚡ tsecurity.de Intelligence

Unlock the Power of TypeScript’s infer Keyword

These days, I want to deep dive into TypeScript's type system. By mastering this, you can become a better developer. At the end of this article, there will be…

Beitrag
0
Seite
0
↗ Quelle (dev.to)
Social ReaktionenReagiere als Erste:r — dein Feedback zählt!

These days, I want to deep dive into TypeScript's type system. By mastering this, you can become a better developer.



At the end of this article, there will be a tip to improve it.



So, take this example:



Implement a generic First that takes an Array T and returns its first element’s type.



For example:




type arr1 = ['a', 'b', 'c']
type arr2 = [3, 2, 1]

type head1 = First<arr1> // expected to be 'a'
type head2 = First<arr2> // expected to be 3






A good way to do it is using Typescript's infer keyword.



You use the infer keyword inside a conditional type



You can imagine this as:

Hey infer, guess the type and give it a name that I can use later.



Well, to solve the previous example, you can use infer like this:




type First<T extends unknown[]> = T extends [infer U, ...unknown[]] ? U : never






Here we say:




The First type accepts a generic T that extends an unknown array.

Then it checks if T matches a tuple whose first element can be inferred as U.

If it does, it returns U (the type of the first element), otherwise it returns never.




So we can use the First type like this




type arr2 = [3, 2, 1]
type head2 = First<arr2> // 3






Now, my wise promise ✨

If you want to become a stronger developer you have to practice on this.



Here is an excellent repo to do it.



Thanks. See you next time 👋🏻

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Unlock the Power of TypeScript’s infer Keyword

Thematisch verwandte Begriffe: Unlock, Power, TypeScripts, infer · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

💬 Kommentare werden geladen…
Zum Aktualisieren ziehen
tsecurity.de Icon
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag