2013-08-29 8 views
3

사과 "기호를 찾을 수 없습니다", 또는 나는 타이프 라이터 문서를 잘못 읽었습니다,하지만 :타이프 라이터 - 다른 파일에서 모듈 기능을 참조 - 나는 모듈이 ..</p> <p>을이에 대한 대답은 간단 경우

/// <reference path="Utils.ts" /> 
Utils.MyFunction(str); 

그러나 다음과 같은 오류가 발생합니다 : :

module Utils{ 

    export function MyFunction(str: string):string { 
     return // something to do with string 
    } 

} 

나는 상단에 내가 참조를 추가 할 수 있도록 다른 .TS 파일 (Clients.ts)이 사용하고 그것을 사용하려고 시도하는

/* 

Compile Error. 
See error list for details 
[path]/Clients.ts(26,39): error TS2095: Could not find symbol 'Utils'. 
[path]/Clients.ts(30,49): error TS2095: Could not find symbol 'Utils'. 
error TS5037: Cannot compile external modules unless the '--module' flag is provided. 


*/ 

아무도 내가 잘못하고있는 것을 설명 할 수 있습니까? 웹 요점 VS2012 및 타이프 라이터 0.9.1

감사를 사용

.

답변

5

답을 직접 찾았습니다. 내가 실제로 찾고 있던 것은 클래스의 정적 메서드였습니다. 아래의 당이이 Client.ts

/// <reference path="Utils.ts" /> 
var x = Utils.MyFunction(str); 
2

error TS5037: Cannot compile external modules unless the '--module' flag is provided. 오류가 발생하면 코드를 가져 오는 것이 아닙니다.

파일의 루트 수준에서 항목을 내 보낸 경우에만이 기능을 사용할 수 있습니다. 예 : 나는에 비디오를했다 : 외부 모듈 로더와 타이프 라이터를 사용하는이 경우

export module Utils{ // Notice the export keyword 

    export function MyFunction(str: string):string { 
     return // something to do with string 
    } 

} 

amd (requirejs/브라우저) 또는 commonjs (노드/서버 측)

PS는 알고해야 제목 : http://www.youtube.com/watch?v=KDrWLMUY0R0&hd=1

+0

에서 일

class Utils { static MyFunction(str: string): string { return //... do something with string } } 

그리고 이건 내 문제가 아니 었습니다. 답변을 아래에 게시합니다. – LiverpoolsNumber9

관련 문제