2017-07-06 12 views
0

正直言って、実際に何が起こっているのかはほとんど分かりません。私はhereと表示されているものに基づいて宣言ファイルを作成しようとしています。ES6形式のExport-from Typescriptモジュール定義(module.d.ts)

私は(これは就業規則に名前を変更し、編集した)これらのファイルを持っている:

project_one

some_interface.ts

import SomeOtherInterface from "some_other_file"; 

interface ThisInterface 
{ 
    aMethodRequiring(aThing: SomeOtherInterface): void; 
} 

export default ThisInterface; 

index.d.ts

export { default as ThisInterface } from "some_interface"; 

tsconfig.json

{ 
    "compilerOptions": { 
    "baseUrl": "src", 
    "noImplicitAny": true, 
    "target": "es2015" 
    }, 
    "exclude": [ 
    "src/**/*.type.ts" 
    ], 
    "include": [ 
    "src/**/*.ts" 
    ] 
} 

project_two

some_class.ts

/// <reference types="project_one" /> 
    /*^This seems to be fine^*/ 

import SomethingInThisProject from "a_file_in_this_project"; 
import { ThisInterface }  from "project_one"; // <=== This is the line that fails. 

class ThatClass 
{ 
    private instanceOfThisInterface : ThisInterface; 

    constructor(saidInstance: ThisInterface) 
    { 
    this.instanceOfThisInterface = saidInstance; 
    } 

    // The useful stuff 
} 

export default ThatClass; 

tsconfig.json

{ 
    "compilerOptions": { 
    "baseUrl": "src", 
    "noImplicitAny": true, 
    "target": "es2015" 
    }, 
    "exclude": [ 
    "src/**/*.type.ts" 
    ], 
    "include": [ 
    "src/**/*.ts" 
    ] 
} 

package.json

{ 
    "name": "project_two", 
    "version": "0.1.0", 
    "description": "A Second Project", 
    "main": "index.js", 
    "repository": "https://github.com/project/two", 
    "author": "Cyle Ven Dawson", 
    "license": "MIT", 
    "devDependencies": { 
    ... 
    }, 
    "dependencies": { 
    ... 
    "project_one": "^0.5.0" 
    } 
} 

活字体がうまくproject_one宣言ファイルを検索します。しかし、それはimportということで私に怒鳴ります。[ts] cannot find module 'project_one'.私は宣言ファイルから何かをインポートしようとするよりも、このコードでもっと間違っていると思いますが、今のところ私はimport行を動作させようとしています。

私は何を誤解しましたか?

+0

package.jsonを表示できますか? 'project_one'は' project_two'の依存関係として正しく登録されていますか? –

+0

@ E_net4 package.jsonの内容が追加されました。 'project_one'は、示されているように依存関係として設定されます。 – dawsonc623

答えて

0

カスタムタイピングの場所は、参照は、より詳細な情報については、documentationをTSconfigのtsconfig.json

{ 
    "compilerOptions": { 
     "typeRoots": [ 
      "./custom_typings", 
      "./node_modules/@types" 
     ] 
    } 
} 

で参照する必要があります。

+0

TypeScriptは宣言をうまく見つけたようです。私のエディタでは、 "go to"機能を使用して、 'node_modules'の下の' project_one'ディレクトリ内の宣言ファイルにホップできます。エラーは 'references'行ではなく' import {ThisInterface} ... '行です。 – dawsonc623

+0

'project_one'から何かをインポートすることができるかどうかを知るために、次の行は機能しますか?' import * as project_one from "project_one" '? – guwere

+0

ちょうど試しました - 同じ '[ts]モジュール 'project_one'.'エラーが見つかりません。 – dawsonc623

関連する問題