1
votes

How would I import ts-topojson into an Angular2 project so I get Typescript typings? I installed the module using npm and tried to include with a simple import statement but the linter said it couldn't find 'topojson'.

import { Topojson } from 'topojson';

This is my first Angular2 project so I'm very new at this so I could possibly be missing a crucial step.

2

2 Answers

3
votes

You could install the package @types/topojson with npm install @types/topojson --save-dev.

Now you can use topojson the following way within a component:

import {topology, feature, ...} from 'topojson';

Or with:

import * as t from '@types/topojson';
1
votes

Try the following:

  1. Make sure the script is loaded into your scripts in .angular-cli.json.
  2. At the top of a file you want to use the library, add declare let Topojson: any;.

Now you can use Topojson without the TS compiler yelling at you, because it will be implied that it's loaded as a script and made available to you during runtime.