Google Antigravity Directory

The #1 directory for Google Antigravity prompts, rules, workflows & MCP servers. Optimized for Gemini 3 agentic development.

Resources

PromptsMCP ServersAntigravity RulesGEMINI.md GuideBest Practices

Company

Submit PromptAntigravityAI.directory

Popular Prompts

Next.js 14 App RouterReact TypeScriptTypeScript AdvancedFastAPI GuideDocker Best Practices

Legal

Privacy PolicyTerms of ServiceContact Us
Featured on FazierVerified on Verified ToolsFeatured on WayfindioAntigravity AI - Featured on Startup FameFeatured on Wired BusinessFeatured on Twelve ToolsListed on Turbo0Featured on findly.toolsFeatured on Aura++That App ShowFeatured on FazierVerified on Verified ToolsFeatured on WayfindioAntigravity AI - Featured on Startup FameFeatured on Wired BusinessFeatured on Twelve ToolsListed on Turbo0Featured on findly.toolsFeatured on Aura++That App Show

© 2026 Antigravity AI Directory. All rights reserved.

The #1 directory for Google Antigravity IDE

This website is not affiliated with, endorsed by, or associated with Google LLC. "Google" and "Gemini" are trademarks of Google LLC.

Antigravity AI Directory
PromptsMCPBest PracticesUse CasesLearn
Home
Prompts
TypeScript Fortgeschrittene Typen Anleitung

TypeScript Fortgeschrittene Typen Anleitung

Meistern Sie fortgeschrittene TypeScript-Typen: Generics, Utility Types, Conditional Types und Type Guards. Vollständige Anleitung für typsichere Entwicklung.

typescripttypengenericsdeutschgermanprogrammierung
by AntigravityAI
⭐0Stars
👁️8Views
.antigravity
# TypeScript Fortgeschrittene Typen

Lernen Sie fortgeschrittene TypeScript-Konzepte für robuste und typsichere Anwendungen.

## Generics (Generische Typen)

```typescript
// Generische Funktion
function ersteElement<T>(array: T[]): T | undefined {
  return array[0];
}

const zahlen = ersteElement([1, 2, 3]); // Typ: number
const texte = ersteElement(["a", "b"]); // Typ: string

// Generische Schnittstelle
interface ApiAntwort<T> {
  daten: T;
  erfolg: boolean;
  nachricht?: string;
  zeitstempel: Date;
}

interface Benutzer {
  id: string;
  name: string;
  email: string;
}

async function holeBenutzer(id: string): Promise<ApiAntwort<Benutzer>> {
  const antwort = await fetch(`/api/benutzer/${id}`);
  return antwort.json();
}
```

## Utility Types (Hilfstypen)

```typescript
interface Produkt {
  id: string;
  name: string;
  preis: number;
  beschreibung: string;
  lagerbestand: number;
  erstelltAm: Date;
}

// Partial - Alle Eigenschaften optional
type ProduktAktualisierung = Partial<Produkt>;

// Pick - Nur bestimmte Eigenschaften
type ProduktVorschau = Pick<Produkt, "id" | "name" | "preis">;

// Omit - Bestimmte Eigenschaften ausschließen
type NeuesProdukt = Omit<Produkt, "id" | "erstelltAm">;

// Required - Alle Eigenschaften erforderlich
type VollständigesProdukt = Required<Produkt>;

// Readonly - Alle Eigenschaften nur lesbar
type UnveränderlichesProdukt = Readonly<Produkt>;

// Record - Objekttyp mit bestimmten Schlüsseln
type ProduktKatalog = Record<string, Produkt>;
```

## Conditional Types (Bedingte Typen)

```typescript
// Einfacher bedingter Typ
type IstString<T> = T extends string ? true : false;

type Test1 = IstString<string>;  // true
type Test2 = IstString<number>;  // false

// Extraktion von Array-Elementtypen
type ArrayElement<T> = T extends (infer E)[] ? E : never;

type ZahlenElement = ArrayElement<number[]>; // number

// Funktion Rückgabetyp extrahieren
type RückgabeTyp<T> = T extends (...args: any[]) => infer R ? R : never;

function holeZahl(): number {
  return 42;
}

type Ergebnis = RückgabeTyp<typeof holeZahl>; // number
```

## Type Guards (Typwächter)

```typescript
interface Hund {
  art: "hund";
  bellen: () => void;
}

interface Katze {
  art: "katze";
  miauen: () => void;
}

type Haustier = Hund | Katze;

// Typwächter-Funktion
function istHund(tier: Haustier): tier is Hund {
  return tier.art === "hund";
}

function tierGeräusch(tier: Haustier) {
  if (istHund(tier)) {
    tier.bellen(); // TypeScript weiß, dass tier ein Hund ist
  } else {
    tier.miauen(); // TypeScript weiß, dass tier eine Katze ist
  }
}

// Assertion-Funktion
function assertIstString(wert: unknown): asserts wert is string {
  if (typeof wert !== "string") {
    throw new Error("Wert muss ein String sein");
  }
}
```

## Mapped Types (Abgebildete Typen)

```typescript
interface Formular {
  benutzername: string;
  email: string;
  passwort: string;
}

// Alle Felder nullable machen
type Nullable<T> = {
  [K in keyof T]: T[K] | null;
};

type NullbaresFormular = Nullable<Formular>;

// Felder mit Getter-Funktionen
type Getter<T> = {
  [K in keyof T as `hole${Capitalize<string & K>}`]: () => T[K];
};

type FormularGetter = Getter<Formular>;
// { holeBenutzername: () => string; holeEmail: () => string; ... }
```

Diese Anleitung hilft deutschen Entwicklern, TypeScript-Typen vollständig zu verstehen.

When to Use This Prompt

This typescript prompt is ideal for developers working on:

  • typescript applications requiring modern best practices and optimal performance
  • Projects that need production-ready typescript code with proper error handling
  • Teams looking to standardize their typescript development workflow
  • Developers wanting to learn industry-standard typescript patterns and techniques

By using this prompt, you can save hours of manual coding and ensure best practices are followed from the start. It's particularly valuable for teams looking to maintain consistency across their typescript implementations.

How to Use

  1. Copy the prompt - Click the copy button above to copy the entire prompt to your clipboard
  2. Paste into your AI assistant - Use with Claude, ChatGPT, Cursor, or any AI coding tool
  3. Customize as needed - Adjust the prompt based on your specific requirements
  4. Review the output - Always review generated code for security and correctness
💡 Pro Tip: For best results, provide context about your project structure and any specific constraints or preferences you have.

Best Practices

  • ✓ Always review generated code for security vulnerabilities before deploying
  • ✓ Test the typescript code in a development environment first
  • ✓ Customize the prompt output to match your project's coding standards
  • ✓ Keep your AI assistant's context window in mind for complex requirements
  • ✓ Version control your prompts alongside your code for reproducibility

Frequently Asked Questions

Can I use this typescript prompt commercially?

Yes! All prompts on Antigravity AI Directory are free to use for both personal and commercial projects. No attribution required, though it's always appreciated.

Which AI assistants work best with this prompt?

This prompt works excellently with Claude, ChatGPT, Cursor, GitHub Copilot, and other modern AI coding assistants. For best results, use models with large context windows.

How do I customize this prompt for my specific needs?

You can modify the prompt by adding specific requirements, constraints, or preferences. For typescript projects, consider mentioning your framework version, coding style, and any specific libraries you're using.

Related Prompts

💬 Comments

Loading comments...