Skip to content

feat: typescript support#389

Merged
mcataford merged 8 commits intopatw0929:masterfrom
andrewsantarin:feature/typescriptSupport
Sep 11, 2021
Merged

feat: typescript support#389
mcataford merged 8 commits intopatw0929:masterfrom
andrewsantarin:feature/typescriptSupport

Conversation

@andrewsantarin
Copy link
Contributor

@andrewsantarin andrewsantarin commented Aug 7, 2021

This PR adds type definition modules so that React TypeScript projects using this library do not need to introduce a drop-in module augmentation of their own, such as in this example gist.

Resolves #346.

Description

  • Added .d.ts modules for all .js files exported by this library.
  • Added compilation script for said .d.ts modules.
  • Added TypeScript component .ts(x) tests in src/components/__tests__ alongside the existing .js tests.
  • Added mentions of TypeScript support, usage examples and contribution instructions in README.md.
  • Added lint support for the TypeScript modules.

Demo:

Locally via yalc

  1. Install yalc globally.
    npm i -g yalc
  2. Prepare react-intl-tel-input for local-only publishing.
    yarn build
    yalc publish --no-scripts # skips prebuild to unblock you
  3. Scaffold a React app.
    npx create-react-app react-intl-tel-input-typescript-demo --template typescript
  4. Install the simulated react-intl-tel-input package.
    yalc add react-intl-tel-input
  5. Use react-intl-tel-input in the React app: App.tsx
    import IntlTelInput from 'react-intl-tel-input';
  6. Inspect IntlTelInput to see its TypeScript definitions.

Remotely via CodeSandbox

A live preview is available with a pre-merge variant of this library: @andrewsantarin/react-intl-tel-input.

Note: The pre-merge variant is somewhat behind in CI changes from master, but the module type definitions are still up to date.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have used ESLint & Prettier to follow the code style of this project.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add TypeScript support

2 participants