2016-04-09 16 views
1

Babel numaralı React projemi TypeScript numaralı telefondan geçiriyorum. Bu her şey gibi görünüyor bir şey TypeScript bana bağırır import:TypeScript'teki her içe aktarma bir * .d.ts dosyası gerektirir mi?

error TS2307: Cannot find module './some-file'.

bu (npm yoluyla) hem dış modülleri için ya (henüz TypeScript olmuştur yfied değil) Projemdeki yerel diğer dosyaları

any olarak içe aktardığım herşeyi işleme sokmak için TypeScript derleyicisine anlatmanın bir yolu var, bu yüzden onlar için tanımlamalar yapmak zorunda değilim?

+0

Dış modül için kesinlikle yazılan bir kod dosyası eklemeniz gerekir. Ortak kitaplığın çoğuna ilişkin (.d.ts) dosya türleri https://github.com/DefinitelyTyped/DefinitelyTyped adresinde bulunabilir. Bu .d.ts dosyasını typings klasörünüze eklemeniz ve /// Ajay

+0

@ Ajay kullanarak kullanmanız gerekir. Her modülde kesinlikle tanımlanmış tanımlamalar yoktur, ayrıca d.ts dosyasına ihtiyacım var gibi görünüyor 'Yerel proje dosyaları için tanımlamalar, –

+1

bundan kaçınmanın yollarını arıyorum. Türleme işlemini tamamlayana kadar" hatalar "ile yaşamanızı öneriyorum, aksi takdirde modası geçecek tanımlar açıklayacaksınız. NoImplicityAny'yi kapattığınızdan emin olun. Hala js çıkışı alacaksınız. –

cevap

0

EVET.

Sen modülleri bunu beyan edebilir ama göreli yolları kullanırken modül isimlerini yönetmek zor olabilir:

declare module "ol/OpenLayers-combined" { 
    var ol: any; 
    export = ol; 
} 
İşte

akım günlük TSC seçenek:

Version 1.8.7 
Syntax: tsc [options] [file ...] 

Examples: tsc hello.ts 
      tsc --out file.js file.ts 
      tsc @args.txt 

Options: 
--allowJs       Allow javascript files to be compiled. 
--allowSyntheticDefaultImports  Allow default imports from modules with no default export. This does not affect code emit, just typechecking. 
--allowUnreachableCode    Do not report errors on unreachable code. 
--allowUnusedLabels     Do not report errors on unused labels. 
-d, --declaration     Generates corresponding '.d.ts' file. 
--experimentalDecorators   Enables experimental support for ES7 decorators. 
--forceConsistentCasingInFileNames Disallow inconsistently-cased references to the same file. 
-h, --help       Print this message. 
--init        Initializes a TypeScript project and creates a tsconfig.json file. 
--jsx KIND       Specify JSX code generation: 'preserve' or 'react' 
--mapRoot LOCATION     Specifies the location where debugger should locate map files instead of generated locations. 
-m KIND, --module KIND    Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015' 
--moduleResolution     Specifies module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). 
--newLine NEWLINE     Specifies the end of line sequence to be used when emitting files: 'CRLF' (dos) or 'LF' (unix). 
--noEmit       Do not emit outputs. 
--noEmitOnError      Do not emit outputs if any errors were reported. 
--noFallthroughCasesInSwitch  Report errors for fallthrough cases in switch statement. 
--noImplicitAny      Raise error on expressions and declarations with an implied 'any' type. 
--noImplicitReturns     Report error when not all code paths in function return a value. 
--noImplicitUseStrict    Do not emit 'use strict' directives in module output. 
--outDir DIRECTORY     Redirect output structure to the directory. 
--outFile FILE      Concatenate and emit output to single file. 
--preserveConstEnums    Do not erase const enum declarations in generated code. 
--pretty KIND      Stylize errors and messages using color and context. (experimental) 
-p DIRECTORY, --project DIRECTORY Compile the project in the given directory. 
--reactNamespace     Specifies the object invoked for createElement and __spread when targeting 'react' JSX emit 
--removeComments     Do not emit comments to output. 
--rootDir LOCATION     Specifies the root directory of input files. Use to control the output directory structure with --outDir. 
--sourceMap       Generates corresponding '.map' file. 
--sourceRoot LOCATION    Specifies the location where debugger should locate TypeScript files instead of source locations. 
--suppressImplicitAnyIndexErrors Suppress noImplicitAny errors for indexing objects lacking index signatures. 
-t VERSION, --target VERSION  Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES2015' (experimental) 
-v, --version      Print the compiler's version. 
-w, --watch       Watch input files. 
@<file>        Insert command line options and files from a file. 

Bildirim noEmitOnError seçenekler. Bu, true değerine ayarlanmamışsa, geçersiz kod çizelgesi bile javascript'i derlemelidir.

+0

Her içe aktarılan modül için bir tip bildirmemenin bir yolunu arıyorum –

+0

Ne zaman sormak derleyici için sizi uyarmak için ne Geçersiz bir modüle referans yaptınız. Bir modülü bildirene kadar bir uyarı göreceksiniz (gerçekten TS hataları yoktur). İçe aktarma ifadesinden tamamen kaçınmalı ve ham gereksinimleri kullanmalısınız. –

İlgili konular