Skip to content

Importing JSON files via the TypeScript's resolveJsonModule property

Notifications You must be signed in to change notification settings

NickIliev/nativescript-resolve-json

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

nativescript-resolve-json

Importing JSON files in NativeScript via the TypeScript's (2.9.x and above) resolveJsonModule property.

Requrments:

  • TypeScript version 2.9.x and above. NativeScript 5.0.0 is automatically createing all TypeScript enabled project with TypeScript versions 3.1.x and above.

New --resolveJsonModule Often in Node.js applications a .json is needed. With TypeScript 2.9, --resolveJsonModule allows for importing, extracting types from and generating .json files.

Example

// config.json
{
    "count": 42,
    "users": [
        {"name": "John", "age": 35},
        {"name": "Ann", "age": 32},
        {"name": "George", "age": 24},
        {"name": "Mary", "age": 27},
        {"name": "Vivian", "age": 21}
    ],
    "env": "debug"
}
// your-typescript-file.ts
import config from "./config.json";

console.log(config.count); // 42
console.log(config.env); // "debug"
// tsconfig.json
{
    "compilerOptions": {
        "module": "commonjs",
        "resolveJsonModule": true,
        "esModuleInterop": true
    }
}

About

Importing JSON files via the TypeScript's resolveJsonModule property

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published