Created
August 21, 2018 09:52
-
-
Save jagomf/e810941e5fdd47e743d1e2d5b8f73da6 to your computer and use it in GitHub Desktop.
Import JSON to TypeScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
import * as data from './example.json'; | |
... | |
const word = (<any>data).name; | |
console.log(word); // output 'testing' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
declare module "*.json" { | |
const value: any; | |
export default value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From https://hackernoon.com/import-json-into-typescript-8d465beded79