📊
Pollz
  • Introduction
  • Quickstart
  • Guides
    • Initializing your app
    • Create a Poll
    • Vote for a Poll
    • Retrieve a Poll
    • Manage Poll Options
    • Listen to update
    • Anonymous Poll
  • Components
    • React
    • React Native
    • Embedded
  • API Reference
    • init()
    • pollOptions()
      • addOption()
      • deleteOption()
      • renameOption()
    • anonymous
      • createAnonymousToken()
      • getAnonymousPoll()
      • voteAnonymously()
    • polls
      • create()
      • get()
      • getAll()
      • vote()
      • rename()
      • deleteOne()
      • listen()
    • pollTypes
      • getAll()
  • Tooling
    • Typescript
    • React
      • usePoll()
      • usePolls()
      • usePollz()
      • usePollTypes()
      • useAnonymousPoll()
Powered by GitBook
On this page
  • Using Pollz-js SDK with TypeScript
  • TypeScript Support
  1. Tooling

Typescript

Using Pollz-js SDK with TypeScript

The Pollz-js SDK is built with TypeScript, providing strong typing and improved developer experience. With TypeScript, you can leverage type-checking capabilities, autocompletion, and enhanced code navigation, making it easier to work with the SDK.

TypeScript Support

When using the Pollz-js SDK in a TypeScript project, you can take advantage of the pre-defined types that come with the SDK. The types are already integrated, providing a seamless development experience and ensuring that your code is type-safe.

Installation

Make sure to install the Pollz-js SDK package in your TypeScript project:

npm install pollz-js

Importing and Using Types

Once installed, you can import the SDK and use the provided types in your TypeScript files:

import { Pollz, PollWithOptions, CreatePollInput, InitInput } from 'pollz-js';

// Example usage
const pollz = new Pollz();

const initInput: InitInput = {
  appId: 'your-app-id',
  appSecret: 'your-app-secret',
};

const pollWithOptions = await pollz.polls.get(1);

const createPollInput: CreatePollInput = {
  name: 'New Poll',
  options: ['Option A', 'Option B', 'Option C'],
  pollTypeId: 1,
};

const createdPoll = await pollz.polls.create(createPollInput);

By using TypeScript with Pollz-js, you can enjoy the benefits of static typing, improved code quality, and better developer tooling. The SDK's types are designed to assist you throughout the development process, providing clarity and confidence in your interactions with the Pollz platform.

For more detailed information about the available types and their usage, refer to the SDK documentation.

PreviousToolingNextReact

Last updated 1 year ago