Subscribed unsubscribe Subscribe Subscribe

TypeScriptでJSONファイルをimportする

webpack2利用時。

custom-typings.d.ts

declare module '*.json' {
  const value: any;
  export default value;
}

foo.ts

import * as data from './data.json';

// ...

Support shorthand ambient module declarations and wildcard chars in module names · Issue #6615 · Microsoft/TypeScript · GitHub