33. Génération TypeScript | Field Forge - Champs personnalisés, conçus pour la vitesse
Télécharger Se connecter

33. Génération TypeScript

Générez des interfaces TypeScript à partir de vos groupes de champs pour des frontends sans tête en toute sécurité de type. Nécessite une licence PRO.

Structure des types générés

typescript
/**
 * Auto-generated by Field Forge v1.0.0
 */

export interface WPImage {
  ID: number;
  url: string;
  width: number;
  height: number;
  alt: string;
  title: string;
  sizes: Record<string, string>;
}

export interface WPFile {
  ID: number;
  url: string;
  filename: string;
  title: string;
  filesize: number;
  mime_type: string;
}

export interface ProductFields {
  price: number;
  sale_price?: number;
  product_gallery?: WPImage[];
  product_badge?: 'new' | 'sale' | 'bestseller' | '';
  product_specs?: Array<{ label?: string; value?: string }>;
}

export interface FieldForgePostTypeMap {
  'product': ProductFields;
  'page': PageFields;
}

Utilisation dans Next.js

typescript
import type { ProductFields, WPImage } from './fieldforge.d.ts';

interface WPPost<T = Record<string, unknown>> {
  id: number;
  title: { rendered: string };
  fieldforge: T;
}

export async function getProduct(id: number): Promise<WPPost<ProductFields>> {
  const res = await fetch(`${process.env.WP_URL}/wp-json/wp/v2/product/${id}`);
  return res.json();
}

const product = await getProduct(42);
const price: number = product.fieldforge.price;

Téléchargement des types

text
GET /wp-admin/admin-ajax.php?action=fieldforge_download_types&format=typescript&nonce=xxx

Renvoie fieldforge.d.ts en tant que téléchargement de fichier.

Assistant IA Forge En ligne

Bonjour ! Je suis l'assistant IA Field Forge. Posez-moi n'importe quelle question sur le plugin — configuration, fonctionnalités, dépannage ou développement.

À l'instant
Propulsé par Forge IA · Parcourir la documentation