2016-04-09 14 views
1

ReactプロジェクトをBabelからTypeScriptに移行しています。TypeScriptのすべてのインポートに* .d.tsファイルが必要ですか?

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

これは(まだyfied TypeScriptされていない)の両方の外部モジュール(npm経由)または私のプロジェクトで地元の他のファイルのために

である:毎回のように私は私を叫ぶ TypeScript import何かようです

TypeScriptコンパイラに私がインポートするものをanyとして扱うように指示する方法はありますか?そのために定義を提供する必要はありませんか?

+0

外部モジュール用のタイプスクリプトファイルが必要です。共通ライブラリのほとんどの入力(.d.ts)ファイルは、https://github.com/DefinitelyTyped/DefinitelyTypedにあります。 – Ajay

+0

@Ajayすべてのモジュールが完全に型定義されているわけではありません。また、 'd.ts 'が必要なように見えます。 'ローカルプロジェクトファイルの定義については、私はそれを避ける方法を探しています –

+1

タイプ化プロセスを終了するまで"エラー "を表示することをお勧めします。そうしないと、時代遅れになる定義を宣言します。あなたは匿名性を完全に無効にしてください。あなたはまだjs出力を取得します。 –

答えて

0

はい。

あなたはモジュールを自分で宣言することができますが、相対パスを使用した場合、モジュール名を管理することが困難なことができます。

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. 

お知らせnoEmitOnError:ここ

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

は、現在の日のTSCのオプションですオプション。それがtrueに設定されていない場合、無効なtypescriptもjavascriptにコンパイルする必要があります。

+0

インポートされたモジュールごとにタイプを宣言しない方法を探しています –

+0

コンパイラがあなたに何を警告しないか無効なモジュールを参照しました。モジュールを宣言するまで、警告が表示されます(本当にTSエラーはありません)。 importステートメントを完全に避け、raw requireを使用する必要があります。 –

関連する問題