Не могу найти метод JavaScript в сгенерированном файле TypeScriptJavascript

Форум по Javascript
Ответить Пред. темаСлед. тема
Anonymous
 Не могу найти метод JavaScript в сгенерированном файле TypeScript

Сообщение Anonymous »

Когда я отправляю форму, один из моих методов JavaScript показывает как неопределенное.

Код: Выделить всё

// Index.cshtml






Click here!!!


Methods formubmitting () и formubmitted определяются в файле TypeScript:

Код: Выделить всё

// 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");
}
Как вы можете видеть выше, в Formsubmitting () - он просто выводит в журнал, сообщающий нам, что находит эту функцию, которую она выполняет. />

Код: Выделить всё

// Javascript/errors.ts

export function hideErrorMessage(): void {
console.log("Is this ever hit? The answer is no...");
}
function hideerrormessage () никогда не получает удар, и вместо этого производит эту ошибку в журналах:
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:3223:31)
at Object.fireWith (jquery.js:3353:7)
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
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Javascript»