나는'm 을 사용하려고 내보내기 및 가져오지만 그것은 작동하지 않은 오류가 발생
여기에는 나의 코드를 HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
@RenderBody()
<script src="~/scripts/user.js"></script>
<script src="~/scripts/main.js"></script>
</body>
</html>
사용자.ts:
export class User {
firstName: string;
lastName: string;
}
습니다.ts
import { User } from "./user";
여기에는 또한 스크린샷의 예외:
다음을 시도 변화
HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
@RenderBody()
<!-- <script src="~/scripts/user.js"></script> --> <!-- not longer needed -->
<script src="~/scripts/main.js"></script>
</body>
</html>
tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"sourceMap": true,
"outFile": "~/scripts/main.js",
"lib": [
"dom",
"es2015",
"es5",
"es6"
]
}
}
이 설정과 함께 당신의 출력은 하나 js 파일 무엇을 할 수 있습니 uglified wunderfull,을 포함하는 모든 파일을 참조에 있습니다.ts. i just don't know if~/작동하거나는 경우를 설정할 필요가 있습니다 상대적인 경로를 설정파일에,나는'm 작업하지 않습니다.
사용자.ts
class User {
firstName: string;
lastName: string;
}
습니다.ts:
/// <reference path="User.ts" />
// import { User } from "./user"; // not needed if referenced
console.log(new User());
모든 참조하 선언을 작성해야의 시작 부분에서 파일
타이프 라이터 기본적으로 사용하여 노드 모듈 해상도입니다. Node.js /CommonJS 사용exports키워드를 사용합니다. 그러나,CommonJS 지 않't 에서 실행하지 않고 브라우저 모듈로더 또는 모듈은 번들러. 따라서,당신은 필요 browserify 또는 웹팩 그것을 실행에 브라우저입니다.
확인 링크 https://www.typescriptlang.org/docs/handbook/gulp.html
을 설정할 수도 있습니다*모듈을 설치해 주세요.*없음컴파일러 옵션섹션에서tsconfig.json*:
{ "compilerOptions":{ "target":"es5", "module":"none" } }