npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gatsby-plugin-typescript

v5.13.1

Published

Adds TypeScript support to Gatsby

Downloads

1,238,688

Readme

gatsby-plugin-typescript

Allows Gatsby to build TypeScript and TSX files. Does NOT run type checking during build (see Caveats).

This plugin is automatically included in Gatsby. The only reason you would need to explicitly use this plugin is if you need to configure its options.

How to customize usage

  1. Include the plugin in your gatsby-config.js file with the specific options
  2. Write your components in TSX or TypeScript.
  3. Run TypeScript directly or with a build tool.
  4. You're good to go.

When creating pages programmatically, you can pass the .tsx filename directly as the component for createPage.

Please note: If packages don't ship with TypeScript definitions you'll need to manually install those type definitions, e.g. for React. A typical Gatsby project would need: npm install --save-dev @types/react @types/react-dom @types/node

Options

When adding this plugin to your gatsby-config.js, you can pass in options to override the default @babel/preset-typescript config.

// gatsby-config.js
module.exports = {
  plugins: [
    {
      resolve: `gatsby-plugin-typescript`,
      options: {
        isTSX: true, // defaults to false
        jsxPragma: `jsx`, // defaults to "React"
        allExtensions: true, // defaults to false
      },
    },
  ],
}

For more detailed documentation on the available options, visit https://babeljs.io/docs/en/babel-preset-typescript#options. To add TypeScript Babel plugins (e.g. @babel/plugin-proposal-decorators), you can try using a custom .babelrc file.

Caveats

This plugin uses babel-plugin-transform-typescript to transpile TypeScript. It does not do type checking. Also since the TypeScript compiler is not involved, the following applies:

Does not support namespaces. Workaround: Move to using file exports, or migrate to using the module { } syntax instead.

Does not support const enums because those require type information to compile. Workaround: Remove the const, which makes it available at runtime.

Does not support export = and import =, because those cannot be compiled to ES.next. Workaround: Convert to using export default and export const, and import x, {y} from "z".

Does not support baseUrl. Workaround: use gatsby-plugin-root-import and configure it to point the baseUrl value (also set baseUrl option in tsconfig.json file).

https://babeljs.io/docs/en/babel-plugin-transform-typescript.html

Type checking

First of all you should set up your IDE so that type errors are surfaced. Visual Studio Code is very good in this regard.

In addition, you can see the instructions in TypeScript-Babel-Starter for setting up a type-check task.