TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

Incude .json file

Open deryl27 opened this issue 11 years ago • 3 comments

How can I include .json file in typescript 1.5

For example : I have level.json file which I need to include in the typescript file

deryl27 avatar Aug 06 '15 14:08 deryl27

Depending on your module format / loader, you can load with that. It's not really something TypeScript itself concerns itself with.

However, one thing I've started doing for HTML templates is embedding them like so:

level.ts

export default `
(JSON / HTML goes here)
`;
import json from './level'; // json is string

i.e. defining it as an exported value using the backtick character. With JSON you could also do:

level.ts

export default JSON.parse(`
(JSON goes here)
`);
import level from './level'; // level is parsed object

jamiewinder avatar Aug 06 '15 19:08 jamiewinder

What do you mean by "include"? if you want to import it as a module, then @jamiewinder's comments would be your best options. you can also look into using amd-dependency tags if you are using amd module loader.

mhegazy avatar Aug 06 '15 20:08 mhegazy

@deryl27 is this still an issue?

mhegazy avatar Aug 10 '15 23:08 mhegazy