खोज…


वाक्य - विन्यास

  • JSON फ़ाइल स्वरूप का उपयोग करता है
  • जावास्क्रिप्ट शैली टिप्पणियों को भी स्वीकार कर सकते हैं

टिप्पणियों

अवलोकन

एक निर्देशिका में tsconfig.json फ़ाइल की उपस्थिति इंगित करती है कि निर्देशिका टाइपस्क्रिप्ट प्रोजेक्ट की जड़ है। Tsconfig.json फ़ाइल रूट फ़ाइलों और कंपाइलर विकल्पों को प्रोजेक्ट को संकलित करने के लिए निर्दिष्ट करती है।

Tsconfig.json का उपयोग करना

  • किसी इनपुट फाइल के साथ tsc को इनवेस्ट करने से, जिस स्थिति में कंपाइलर tsconfig.json फाइल को वर्तमान डायरेक्टरी में शुरू करता है और पेरेंट डायरेक्टरी चेन को जारी रखता है।
  • कोई इनपुट फ़ाइलों और एक -project (या सिर्फ -p) कमांड लाइन विकल्प के साथ tsc को शामिल करके, जो tsconfig.json फ़ाइल वाली निर्देशिका के पथ को निर्दिष्ट करता है। जब कमांड लाइन पर इनपुट फाइलें निर्दिष्ट की जाती हैं, तो tsconfig.json फाइलें होती हैं

विवरण

"compilerOptions" गुण को छोड़ा जा सकता है, जिस स्थिति में संकलक की चूक का उपयोग किया जाता है। समर्थित कंपाइलर विकल्पों की हमारी पूरी सूची देखें।

यदि कोई "files" संपत्ति tsconfig.json में मौजूद नहीं है, तो संकलक निर्देशिका और उपनिर्देशिकाओं में सभीस्क्रिप्ट (* .ts या * .tsx) फ़ाइलों को शामिल करने के लिए कंपाइलर डिफॉल्ट करता है। जब "फाइलें" संपत्ति मौजूद होती है, तो केवल निर्दिष्ट फाइलें शामिल होती हैं।

यदि "exclude" संपत्ति निर्दिष्ट की जाती है, तो कंपाइलर में सभी टाइपस्क्रिप्ट (* .ts या * .tsx) फाइलें शामिल होती हैं, जिसमें निर्देशिका और उपनिर्देशिका फाइलें उन फाइलों या फ़ोल्डरों को छोड़कर जिन्हें बाहर रखा गया है।

"files" संपत्ति का उपयोग "बहिष्कृत" संपत्ति के साथ संयोजन में नहीं किया जा सकता है। यदि दोनों निर्दिष्ट हैं तो "फाइलें" संपत्ति पूर्वता लेती हैं।

"files" संपत्ति में निर्दिष्ट लोगों द्वारा संदर्भित किसी भी फाइल को भी शामिल किया गया है। इसी तरह, यदि कोई फ़ाइल B.ts को किसी अन्य फ़ाइल A.ts द्वारा संदर्भित करती है, तो B.ts को तब तक बाहर नहीं किया जा सकता जब तक कि संदर्भित फ़ाइल A.ts को "बहिष्कृत" सूची में निर्दिष्ट न किया गया हो।

एक tsconfig.json फ़ाइल को पूरी तरह से खाली करने की अनुमति है, जिसमें डिफ़ॉल्ट कंपाइलर विकल्पों के साथ निर्देशिका और उपनिर्देशिका में सभी फ़ाइलों को संकलित किया गया है।

कमांड लाइन पर निर्दिष्ट कंपाइलर विकल्प tsconfig.json फ़ाइल में निर्दिष्ट लोगों को ओवरराइड करते हैं।

योजना

स्कीमा पर पाया जा सकता है: http://json.schemastore.org/tsconfig

Tsconfig.json के साथ टाइपस्क्रिप्ट प्रोजेक्ट बनाएं

Tsconfig.json फ़ाइल की उपस्थिति इंगित करती है कि वर्तमान निर्देशिका टाइपस्क्रिप्ट सक्षम प्रोजेक्ट का मूल है।

टाइपस्क्रिप्ट प्रोजेक्ट को प्रारंभ करना, या tsconfig.json फ़ाइल को बेहतर तरीके से रखना, निम्नलिखित कमांड के माध्यम से किया जा सकता है:

tsc --init

टाइपस्क्रिप्ट v2.3.0 और इससे उच्चतर के रूप में यह डिफ़ॉल्ट रूप से निम्नलिखित tsconfig.json बनाएगा:

{
  "compilerOptions": {
    /* Basic Options */                       
    "target": "es5",                          /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */
    "module": "commonjs",                     /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'. */
    // "lib": [],                             /* Specify library files to be included in the compilation:  */
    // "allowJs": true,                       /* Allow javascript files to be compiled. */
    // "checkJs": true,                       /* Report errors in .js files. */
    // "jsx": "preserve",                     /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
    // "declaration": true,                   /* Generates corresponding '.d.ts' file. */
    // "sourceMap": true,                     /* Generates corresponding '.map' file. */
    // "outFile": "./",                       /* Concatenate and emit output to single file. */
    // "outDir": "./",                        /* Redirect output structure to the directory. */
    // "rootDir": "./",                       /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
    // "removeComments": true,                /* Do not emit comments to output. */
    // "noEmit": true,                        /* Do not emit outputs. */
    // "importHelpers": true,                 /* Import emit helpers from 'tslib'. */
    // "downlevelIteration": true,            /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
    // "isolatedModules": true,               /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
                                              
    /* Strict Type-Checking Options */        
    "strict": true                            /* Enable all strict type-checking options. */
    // "noImplicitAny": true,                 /* Raise error on expressions and declarations with an implied 'any' type. */
    // "strictNullChecks": true,              /* Enable strict null checks. */
    // "noImplicitThis": true,                /* Raise error on 'this' expressions with an implied 'any' type. */
    // "alwaysStrict": true,                  /* Parse in strict mode and emit "use strict" for each source file. */
                                              
    /* Additional Checks */                   
    // "noUnusedLocals": true,                /* Report errors on unused locals. */
    // "noUnusedParameters": true,            /* Report errors on unused parameters. */
    // "noImplicitReturns": true,             /* Report error when not all code paths in function return a value. */
    // "noFallthroughCasesInSwitch": true,    /* Report errors for fallthrough cases in switch statement. */
                                              
    /* Module Resolution Options */           
    // "moduleResolution": "node",            /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
    // "baseUrl": "./",                       /* Base directory to resolve non-absolute module names. */
    // "paths": {},                           /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
    // "rootDirs": [],                        /* List of root folders whose combined content represents the structure of the project at runtime. */
    // "typeRoots": [],                       /* List of folders to include type definitions from. */
    // "types": [],                           /* Type declaration files to be included in compilation. */
    // "allowSyntheticDefaultImports": true,  /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
                                              
    /* Source Map Options */                  
    // "sourceRoot": "./",                    /* Specify the location where debugger should locate TypeScript files instead of source locations. */
    // "mapRoot": "./",                       /* Specify the location where debugger should locate map files instead of generated locations. */
    // "inlineSourceMap": true,               /* Emit a single file with source maps instead of having a separate file. */
    // "inlineSources": true,                 /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
                                              
    /* Experimental Options */                
    // "experimentalDecorators": true,        /* Enables experimental support for ES7 decorators. */
    // "emitDecoratorMetadata": true,         /* Enables experimental support for emitting type metadata for decorators. */
  }
}

अधिकांश, यदि सभी नहीं हैं, तो विकल्प स्वचालित रूप से केवल नंगे आवश्यकताओं के साथ उत्पन्न होते हैं जो अनियंत्रित होते हैं।

टाइपस्क्रिप्ट के पुराने संस्करण, उदाहरण के लिए v2.0.x और निचला, जैसे tsconfig.json उत्पन्न करेंगे:

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es5",
        "noImplicitAny": false,
        "sourceMap": false
    }
}

compileOnSave

सहेजने के लिए दिए गए tsconfig.json के लिए सभी फ़ाइलों को उत्पन्न करने के लिए IDE के लिए एक शीर्ष-स्तरीय संपत्ति compileOnSave सिग्नल सेट करना।

{
    "compileOnSave": true,
    "compilerOptions": {
        ...
    },
    "exclude": [
        ...
    ]
}

यह सुविधा टाइपस्क्रिप्ट 1.8.4 और उसके बाद से उपलब्ध है, लेकिन इसे सीधे आईडीई द्वारा समर्थित होने की आवश्यकता है। वर्तमान में, समर्थित आईडीई के उदाहरण हैं:

टिप्पणियाँ

एक tsconfig.json फ़ाइल में ECMAScript के समान नियमों का उपयोग करते हुए, दोनों लाइन और ब्लॉक टिप्पणियाँ हो सकती हैं।

//Leading comment
{
    "compilerOptions": {
        //this is a line comment
        "module": "commonjs", //eol line comment
        "target" /*inline block*/ : "es5",
        /* This is a
        block
        comment */
    }
}
/* trailing comment */

कम प्रोग्रामिंग त्रुटियों के लिए कॉन्फ़िगरेशन

टाइपिंग को मजबूर करने और अधिक उपयोगी त्रुटियां प्राप्त करने के लिए बहुत अच्छे कॉन्फ़िगरेशन हैं जो डिफ़ॉल्ट रूप से सक्रिय नहीं हैं।

{
  "compilerOptions": {

    "alwaysStrict": true, // Parse in strict mode and emit "use strict" for each source file. 

    // If you have wrong casing in referenced files e.g. the filename is Global.ts and you have a /// <reference path="global.ts" /> to reference this file, then this can cause to unexpected errors. Visite: http://stackoverflow.com/questions/36628612/typescript-transpiler-casing-issue
    "forceConsistentCasingInFileNames": true, // Disallow inconsistently-cased references to the same file.

    // "allowUnreachableCode": false, // Do not report errors on unreachable code. (Default: False)
    // "allowUnusedLabels": false, // Do not report errors on unused labels. (Default: False)

    "noFallthroughCasesInSwitch": true, // Report errors for fall through cases in switch statement.
    "noImplicitReturns": true, // Report error when not all code paths in function return a value.

    "noUnusedParameters": true, // Report errors on unused parameters.
    "noUnusedLocals": true, // Report errors on unused locals.

    "noImplicitAny": true, // Raise error on expressions and declarations with an implied "any" type.
    "noImplicitThis": true, // Raise error on this expressions with an implied "any" type.

    "strictNullChecks": true, // The null and undefined values are not in the domain of every type and are only assignable to themselves and any.

    // To enforce this rules, add this configuration.
    "noEmitOnError": true     // Do not emit outputs if any errors were reported.
  }
}

पर्याप्त नहीं? यदि आप एक हार्ड कोडर हैं और अधिक चाहते हैं, तो आप अपने टाइपस्क्रिप्ट फ़ाइलों को tsc के साथ संकलित करने से पहले tslint के साथ जांचना चाह सकते हैं। यहां तक कि कड़े कोड के लिए tslint को कॉन्फ़िगर करने का तरीका जांचें।

preserveConstEnums

टाइपप्रति costant enumerables, के माध्यम से घोषित समर्थन करता है, const enum

यह आमतौर पर सिर्फ सिंटैक्स चीनी होता है क्योंकि संकलित जावास्क्रिप्ट संकलित जावास्क्रिप्ट में सम्मिलित होते हैं।

उदाहरण के लिए निम्न कोड

const enum Tristate {
    True,
    False,
    Unknown
}

var something = Tristate.True;

के लिए संकलित करता है

var something = 0;

(: यदि आप विकास कोड पर पठनीयता इच्छा हो सकती है यानी) में tsconfig.json यह आप सेट करने के लिए है करने के लिए, हालांकि इनलाइन करने से कार्यक्षमता लाभ, आप enums रखने के लिए costant भले ही पसंद कर सकते हैं preserveConstEnums में clausole compilerOptions को true

{
    "compilerOptions": {
        "preserveConstEnums" = true,
        ...
    },
    "exclude": [
        ...
    ]
}

इस तरह से पिछले उदाहरण को किसी अन्य एंथम के रूप में संकलित किया जाएगा, जैसा कि निम्नलिखित स्निपेट में दिखाया गया है।

var Tristate;
(function (Tristate) {
    Tristate[Tristate["True"] = 0] = "True";
    Tristate[Tristate["False"] = 1] = "False";
    Tristate[Tristate["Unknown"] = 2] = "Unknown";
})(Tristate || (Tristate = {}));

var something = Tristate.True


Modified text is an extract of the original Stack Overflow Documentation
के तहत लाइसेंस प्राप्त है CC BY-SA 3.0
से संबद्ध नहीं है Stack Overflow