Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
WP_Post
✓ import { WP_Post } from 'wp-types'
✗ import WP_Post from 'wp-types'
Named export, not default. Requires TypeScript 4.0+ with esModuleInterop.
WP_REST_API_Post
✓ import { WP_REST_API_Post } from 'wp-types'
✗ import { WP_REST_API_Post } from 'wp-types/lib/post'
All types are exported from the package root; no subpath exports exist.
WP_User
✓ import { WP_User } from 'wp-types'
✗ const WP_User = require('wp-types').WP_User
Both CJS require and ESM import work, but named import is preferred.
WP_Error
✓ import type { WP_Error } from 'wp-types'
✗ import { WP_Error } from 'wp-types'
WP_Error is a type-only interface; use `import type` when not using at runtime.
WP_REST_API_Blocks
✓ import { WP_REST_API_Blocks } from 'wp-types'
✗ import { WP_REST_API_Block } from 'wp-types'
Array types have plural names, singular types are for single items.
Imports and sample usage of WP_Post, WP_REST_API_Post, and WP_User types demonstrating PHP object and REST API response shapes.
import type { WP_Post, WP_REST_API_Post, WP_User } from 'wp-types';
const post: WP_Post = {
ID: 1,
post_author: '1',
post_date: '2024-01-01 00:00:00',
post_date_gmt: '2024-01-01 00:00:00',
post_content: 'Hello World',
post_title: 'Hello',
post_excerpt: '',
post_status: 'publish',
comment_status: 'open',
ping_status: 'open',
post_password: '',
post_name: 'hello',
to_ping: '',
pinged: '',
post_modified: '2024-01-01 00:00:00',
post_modified_gmt: '2024-01-01 00:00:00',
post_content_filtered: '',
post_parent: 0,
guid: 'https://example.com/?p=1',
menu_order: 0,
post_type: 'post',
post_mime_type: '',
comment_count: '0',
filter: 'raw',
};
const apiPost: WP_REST_API_Post = {
id: 1,
date: '2024-01-01T00:00:00',
date_gmt: '2024-01-01T00:00:00',
guid: { rendered: 'https://example.com/?p=1' },
modified: '2024-01-01T00:00:00',
modified_gmt: '2024-01-01T00:00:00',
slug: 'hello',
status: 'publish',
type: 'post',
link: 'https://example.com/hello',
title: { rendered: 'Hello' },
content: { rendered: '<p>Hello World</p>', protected: false },
excerpt: { rendered: '', protected: false },
author: 1,
featured_media: 0,
comment_status: 'open',
ping_status: 'open',
sticky: false,
template: '',
format: 'standard',
meta: {},
categories: [1],
tags: [],
_links: {
self: [{ href: 'https://example.com/wp-json/wp/v2/posts/1' }],
collection: [{ href: 'https://example.com/wp-json/wp/v2/posts' }],
about: [{ href: 'https://example.com/wp-json/wp/v2/types/post' }],
author: [{ href: 'https://example.com/wp-json/wp/v2/users/1' }],
replies: [{ href: 'https://example.com/wp-json/wp/v2/comments?post=1' }],
'version-history': [{ href: 'https://example.com/wp-json/wp/v2/posts/1/revisions', count: 0 }],
'wp:attachment': [{ href: 'https://example.com/wp-json/wp/v2/media?parent=1' }],
'wp:term': [{ href: 'https://example.com/wp-json/wp/v2/categories?post=1' }, { href: 'https://example.com/wp-json/wp/v2/tags?post=1' }],
curies: [{ name: 'wp', href: 'https://api.w.org/{rel}', templated: true }],
},
};
const user: WP_User = {
ID: 1,
user_login: 'admin',
user_pass: '',
user_nicename: 'admin',
user_email: 'admin@example.com',
user_url: '',
user_registered: '2024-01-01 00:00:00',
user_activation_key: '',
user_status: 0,
display_name: 'Admin',
};
console.log(post, apiPost, user);
Errors
Common errors & fixes
Type error: Property 'post_author' is missing in type '{ ... }' but required in type 'WP_Post'
Missing required property in object literal assigned to WP_Post type.
fixAdd all required properties as defined in WP_Post interface, including 'post_author', 'post_date', etc.
Module '"wp-types"' has no exported member 'WP_REST_API_Post'. Did you mean to use 'import WP_REST_API_Post from "wp-types"' instead?
Using default import for a named export or missing the type from the package.
fixUse named import: `import { WP_REST_API_Post } from 'wp-types'`. Cannot find module 'wp-types' or its corresponding type declarations.
Package not installed or type resolution misconfigured.
fixRun `npm install wp-types --save-dev` and ensure tsconfig.json includes 'node_modules/@types' or 'types' field.
Type 'string' is not assignable to type 'number' in property 'ID'
Mixing up PHP object (ID is number) and REST API (id is number) types, but assigning string to ID.
fixEnsure ID is a number, e.g., `ID: 1` not `ID: '1'`.
Audit
Dependencies
No dependency data recorded yet.