FastComments TypeScript Types

3.0.13 · active · verified Sun Apr 19

This package, `fastcomments-typescript`, provides a comprehensive set of TypeScript type definitions for interacting with the FastComments platform. It includes types for API models, such as comment data structures and user profiles, as well as request and response bodies for various API operations (e.g., creating or updating comments). Additionally, it defines types for widget configurations, ensuring type safety when embedding and customizing the FastComments widget within a TypeScript application. The current stable version is 3.0.13. Release cadence typically aligns with updates to the FastComments API and SDK, ensuring type definitions remain consistent with the latest platform features. Its key differentiator is providing official, precise type guidance for developers integrating with FastComments, minimizing runtime errors related to data shape mismatches.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to import and use core FastComments types (Comment, CreateCommentRequest, WidgetConfig) to define data structures, enhancing type safety in your application.

import type { Comment, CreateCommentRequest, WidgetConfig } from 'fastcomments-typescript';

// Example: Defining a comment object received from the API
const myComment: Comment = {
  id: 'some-comment-id-123',
  userId: 'user-456',
  text: 'This is an example comment.',
  createdAt: new Date().toISOString(),
  author: {
    id: 'user-456',
    displayName: 'Example User',
    profileUrl: 'https://example.com/users/456',
    avatarURL: 'https://example.com/avatars/456.png'
  },
  status: 'APPROVED',
  threadId: 'blog-post-abc'
};

// Example: Defining a request payload for creating a new comment
const newCommentPayload: CreateCommentRequest = {
  text: 'A new comment to be posted on the thread.',
  threadId: 'blog-post-xyz',
  url: 'https://example.com/blog/post-xyz',
  // Additional optional fields like parentId, anonymousUser, etc., can be added here
};

// Example: Defining widget configuration for embedding FastComments
const myWidgetConfig: WidgetConfig = {
  tenantId: 'your-tenant-id-here',
  url: 'https://example.com/current-page-url',
  // Many more configuration options are available
  theme: 'dark',
  replyingPlaceholderText: 'Write your reply...', 
  maxCommentLength: 1000,
  disableVoting: false
};

console.log('Defined Comment:', myComment);
console.log('Defined New Comment Payload:', newCommentPayload);
console.log('Defined Widget Configuration:', myWidgetConfig);

// These types provide compile-time safety when interacting with FastComments data and APIs.
function handleIncomingComment(commentData: Comment) {
  console.log(`Received comment from ${commentData.author.displayName}: ${commentData.text.substring(0, 50)}...`);
}

handleIncomingComment(myComment);

view raw JSON →