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 型システム完全ガイド

TypeScript 型システム完全ガイド

TypeScriptの高度な型をマスター:ジェネリクス、ユーティリティ型、条件型、型ガード。型安全な開発のための完全ガイド。

typescript型ジェネリクス日本語japaneseプログラミング
by AntigravityAI
⭐0Stars
👁️3Views
.antigravity
# TypeScript 型システム完全ガイド

Google Antigravity IDEでTypeScriptの高度な型システムをマスターしましょう。このガイドではジェネリクス、条件型、型安全なパターンについて解説します。

## なぜ高度な型が必要か?

TypeScriptの高度な型システムはコンパイル時の安全性を提供します。Google Antigravity IDEのGemini 3エンジンがインテリジェントな型推論を提供します。

## ジェネリクスの基礎

```typescript
// 基本的なジェネリック関数
function identity<T>(value: T): T {
  return value;
}

// 制約付きジェネリック
function getProperty<T, K extends keyof T>(obj: T, key: K): T[K] {
  return obj[key];
}

// ジェネリッククラス
class Repository<T extends { id: string }> {
  private items: Map<string, T> = new Map();
  
  add(item: T): void {
    this.items.set(item.id, item);
  }
  
  get(id: string): T | undefined {
    return this.items.get(id);
  }
  
  getAll(): T[] {
    return Array.from(this.items.values());
  }
  
  filter<K extends keyof T>(key: K, value: T[K]): T[] {
    return this.getAll().filter((item) => item[key] === value);
  }
}

// 使用例
interface User {
  id: string;
  name: string;
  role: "admin" | "user";
}

const userRepo = new Repository<User>();
userRepo.add({ id: "1", name: "田中", role: "admin" });
const admins = userRepo.filter("role", "admin");
```

## 条件型

```typescript
// 基本的な条件型
type IsString<T> = T extends string ? true : false;

// 型抽出のためのinferキーワード
type ReturnType<T> = T extends (...args: unknown[]) => infer R ? R : never;

type ArrayElement<T> = T extends (infer E)[] ? E : never;

type PromiseValue<T> = T extends Promise<infer V> ? V : T;

// 分配条件型
type NonNullable<T> = T extends null | undefined ? never : T;

// 実践例:APIレスポンスの処理
type ApiResponse<T> = T extends { error: infer E }
  ? { success: false; error: E }
  : { success: true; data: T };

// 深いreadonly
type DeepReadonly<T> = T extends object
  ? { readonly [K in keyof T]: DeepReadonly<T[K]> }
  : T;
```

## マップ型

```typescript
// 基本的なマップ型
type Optional<T> = {
  [K in keyof T]?: T[K];
};

// キーのリマッピング
type Getters<T> = {
  [K in keyof T as `get${Capitalize<string & K>}`]: () => T[K];
};

type Setters<T> = {
  [K in keyof T as `set${Capitalize<string & K>}`]: (value: T[K]) => void;
};

// イベントハンドラー
type EventHandlers<T> = {
  [K in keyof T as `on${Capitalize<string & K>}Change`]: (
    newValue: T[K],
    oldValue: T[K]
  ) => void;
};

interface User {
  name: string;
  age: number;
}

type UserGetters = Getters<User>;
// { getName: () => string; getAge: () => number; }
```

## テンプレートリテラル型

```typescript
// ルートパラメータの抽出
type ExtractParams<T extends string> =
  T extends `${string}:${infer Param}/${infer Rest}`
    ? Param | ExtractParams<Rest>
    : T extends `${string}:${infer Param}`
    ? Param
    : never;

type RouteParams = ExtractParams<"/users/:userId/posts/:postId">;
// "userId" | "postId"

// 型安全なイベントエミッター
type EventName<T extends string> = `${T}:${string}`;

type ParseEvent<T> = T extends `${infer Category}:${infer Name}`
  ? { category: Category; name: Name }
  : never;
```

## ユーティリティ型パターン

```typescript
// ディープパーシャル
type DeepPartial<T> = T extends object
  ? { [K in keyof T]?: DeepPartial<T[K]> }
  : T;

// 値の型でピック
type PickByType<T, V> = {
  [K in keyof T as T[K] extends V ? K : never]: T[K];
};

// 必須キーのみ
type RequiredKeys<T> = {
  [K in keyof T]-?: undefined extends T[K] ? never : K;
}[keyof T];

// 二つの型をマージ
type Merge<T, U> = Omit<T, keyof U> & U;
```

## タイプガード

```typescript
// カスタムタイプガード
function isUser(value: unknown): value is User {
  return (
    typeof value === "object" &&
    value !== null &&
    "id" in value &&
    "name" in value
  );
}

// 判別可能なユニオンガード
type Result<T, E = Error> =
  | { success: true; data: T }
  | { success: false; error: E };

function isSuccess<T, E>(result: Result<T, E>): result is { success: true; data: T } {
  return result.success === true;
}

// アサーション関数
function assertDefined<T>(value: T | undefined): asserts value is T {
  if (value === undefined) {
    throw new Error("値が未定義です");
  }
}
```

## ベストプラクティス

- 再利用可能な型安全コードにジェネリクスを使用
- 型変換に条件型を適用
- オブジェクト操作にマップ型を活用
- ランタイム検証にタイプガードを作成
- 複雑な型をJSDocでドキュメント化

Google Antigravity IDEはインテリジェントな型推論を提供し、TypeScriptコードに最適な高度な型パターンを提案します。

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...