Skip to content

GitHub Issue: TypeScript Error with artifact() - ZodObject Missing Required Properties #118

@AviOfLagos

Description

@AviOfLagos

GitHub Issue: TypeScript Error with artifact() - ZodObject Missing Required Properties

Package: @ai-sdk-tools/[email protected]
Environment:

  • TypeScript: 5.7.2
  • Zod: 4.1.13
  • AI SDK: 5.0.101
  • Node: 20.x

🐛 Bug Description

When using the artifact() helper from @ai-sdk-tools/artifacts with even the simplest Zod schemas, TypeScript reports that the ZodObject type is incompatible with the expected type parameter.

📋 Error Message

Argument of type 'ZodObject<{ name: ZodString; industry: ZodString; tagline: ZodString; status: ZodEnum<["analyzing", "complete"]>; progress: ZodNumber; }, "strip", ZodTypeAny, { ... }, { ... }>' is not assignable to parameter of type 'ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>'.

Type 'ZodObject<...>' is missing the following properties from type 'ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>': def, type, check, clone, and 14 more.

🔄 Reproduction Steps

Minimal Example

import { artifact } from '@ai-sdk-tools/artifacts';
import { z } from 'zod';

// Even the simplest flat schema fails
export const BrandProfileArtifact = artifact('brand_profile', z.object({
  name: z.string(),
  industry: z.string(),
  tagline: z.string(),
  status: z.enum(['analyzing', 'complete']),
  progress: z.number().min(0).max(1),
}));
// ❌ TypeScript Error: ZodObject is not assignable to parameter type

What We Tried

  1. Super simple schemas - Still fails
export const SimpleArtifact = artifact('simple', z.object({
  title: z.string(),
  status: z.enum(['writing', 'done']),
}));
// ❌ Same error
  1. Removed all nested objects - Still fails
export const FlatArtifact = artifact('flat', z.object({
  text: z.string(),
  count: z.number(),
}));
// ❌ Same error
  1. Removed .min()/.max() - Still fails
export const NoConstraintsArtifact = artifact('no_constraints', z.object({
  name: z.string(),
  value: z.number(),
}));
// ❌ Same error

🤔 Expected Behavior

Based on the documentation at https://ai-sdk-tools.dev/artifacts, this should work:

const Dashboard = artifact('dashboard', z.object({
  title: z.string(),
  metrics: z.object({
    revenue: z.number(),
    users: z.number(),
  }),
  status: z.enum(['loading', 'complete']),
  progress: z.number(),
}))

The schema should be accepted and artifact streaming should work.

🔍 Actual Behavior

TypeScript rejects ALL Zod schemas passed to artifact(), even the simplest ones, with the error that ZodObject is missing internal properties like def, type, check, clone.

💻 Full Code Context

File: lib/common/midday-artifacts.ts

/**
 * Attempting to use Midday artifacts as documented
 */
import { artifact } from '@ai-sdk-tools/artifacts';
import { z } from 'zod';

// Article artifact for WriterAgent
export const ArticleArtifact = artifact('article', z.object({
  title: z.string(),
  content: z.string(),
  wordCount: z.number(),
  status: z.enum(['writing', 'reviewing', 'complete']),
  progress: z.number().min(0).max(1),
}));
// ❌ Error on this line

// Social Post artifact for RepurposeAgent  
export const SocialPostArtifact = artifact('social_post', z.object({
  platform: z.enum(['twitter', 'linkedin', 'instagram']),
  content: z.string(),
  hashtags: z.string(),
  status: z.enum(['generating', 'complete']),
  progress: z.number().min(0).max(1),
}));
// ❌ Error on this line too

tsconfig.json (relevant settings):

{
  "compilerOptions": {
    "target": "ES2017",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "bundler",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true,
    "paths": {
      "@/*": ["./*"]
    }
  }
}

🔧 Attempted Workarounds

1. Type Assertion (works but defeats type safety)

export const ArticleArtifact = artifact('article', z.object({
  title: z.string(),
  status: z.enum(['writing', 'done']),
}) as any);
// ✅ Compiles but loses all type safety

2. Different moduleResolution

Changed moduleResolution from "bundler" to "node16" - didn't help.

3. Importing from different path

import { artifact } from '@ai-sdk-tools/artifacts/dist/index';
// Still same error

❓ Questions

  1. Is there a specific Zod version required? (Currently using 4.1.13)
  2. Is there a different way to define artifact schemas?
  3. Are there working TypeScript examples in a repository we can reference?
  4. Is this a known issue with a workaround?

🌍 Environment

@ai-sdk-tools/artifacts: 1.2.0
@ai-sdk-tools/store: 1.2.0
ai: 5.0.101
zod: 4.1.13
typescript: 5.7.2
next: 15.1.3

📦 Package Installation

pnpm add @ai-sdk-tools/artifacts @ai-sdk-tools/store
pnpm add ai@latest # Upgraded to v5 for compatibility

🙏 Request

Any guidance would be appreciated:

  • Is this a type definition issue that can be fixed?
  • Is there proper TypeScript usage documentation?
  • Should we use a different approach for defining artifacts?

Thank you for the amazing toolkit! The Store and Memory features are working great. Just struggling with artifacts specifically.


Additional Context: We're building a multi-agent brand engine and want to stream structured outputs from our agents to React components using the useArtifact hook. Everything else in the SDK works perfectly for now.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions