Код: Выделить всё
// Index.cshtml
Click here!!!
Код: Выделить всё
// Javascript/site.ts
import { hideErrorMessage } from './errors';
export function formSubmitted(result: object): void {
console.log("This gets hit");
hideErrorMessage();
console.log("This does not get hit");
}
export function formSubmitting(): void {
console.log("hitting form submitting");
}
Код: Выделить всё
// Javascript/errors.ts
export function hideErrorMessage(): void {
console.log("Is this ever hit? The answer is no...");
}
Uncaught TypeError: Cannot read properties of undefined (reading 'hideErrorMessage')
at HTMLFormElement.formSubmitted (site.ts:5:5)
at Object.complete (jquery.unobtrusive-ajax.js:101:92)
at fire (jquery.js
at Object.fireWith (jquery.js
at done (jquery.js:9642:21)
at XMLHttpRequest. (jquery.js:9888:9)
У меня есть мой tsconfig.json для составления файлов TS здесь:
{
"compilerOptions": {
"noImplicitAny": false,
"noEmitOnError": true,
"removeComments": false,
"sourceMap": true,
"target": "es5",
"outDir": "wwwroot/js/compiled",
"moduleResolution": "node",
"allowUnreachableCode": false,
"alwaysStrict": true,
"esModuleInterop": true,
"types": [ "jquery" ]
},
"compileOnSave": true,
"exclude": [
"node_modules",
"wwwroot"
]
}
< /code>
И это, кажется, работает, потому что он собирает файлы так, как я ожидал бы: < /p>
// wwwroot/js/compiled/site.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.formSubmitted = formSubmitted;
exports.formSubmitting = formSubmitting;
var errors_1 = require("./errors");
function formSubmitted(result) {
console.log("This gets hit");
(0, errors_1.hideErrorMessage)();
console.log("This does not get hit");
}
function formSubmitting() {
console.log("hitting form submitting");
}
//# sourceMappingURL=site.js.map
< /code>
// wwwroot/js/compiled/errors.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.hideErrorMessage = hideErrorMessage;
function hideErrorMessage() {
console.log("Is this ever hit? The answer is no...");
}
//# sourceMappingURL=errors.js.map
< /code>
So looking at the compiled output, hideErrorMessage() exists. So I don't understand why it is showing as undefined?
I set up an example in GitHub if that is helpful.
Подробнее здесь: https://stackoverflow.com/questions/796 ... cript-file