///<reference path="HtmlElementsAction.ts" />
///<reference path="DesktopSocket.ts" />
module Pong {
export class webPage extends HtmlElementsAction {
private socket;
constructor() {
super();
this.socket = new DesktopSocket(this);
}
}
}
I've this code.
When I'm executing it, in browser's console is error:
Uncaught TypeError: undefined is not a function
Error is on new DesktopSocket(this);
What am I doing wrong?
Common error. Check the order of your script tags or if compiling with "out" the order of arguments to tsc.
Related
When debugging typescript code from my testcases in Intellij Idea I get the following error inside the Evaluate window (Alt + F8):
ReferenceError: InternalServerException is not defined
at eval (eval at getStatusCodeAndResponse (C:\Users\<user>\Documents\Projecten\stations-api\app\common\error-handler.ts:17:13), <anonymous>:1:1)
at Object.getStatusCodeAndResponse (C:\Users\<user>\Documents\Projecten\stations-api\app\common\error-handler.ts:17:13)
at Lambda.handler (C:\Users\<user>\Documents\Projecten\stations-api\app\get-guiding-lines-combinations.ts:38:20)
at Lambda.<anonymous> (C:\Users\<user>\Documents\Projecten\stations-api\node_modules\#aws-lambda-powertools\metrics\src\Metrics.ts:277:41)
at Lambda.<anonymous> (C:\Users\<user>\Documents\Projecten\stations-api\node_modules\#aws-lambda-powertools\logger\src\Logger.ts:337:41)
at Lambda.<anonymous> (C:\Users\<user>\Documents\Projecten\stations-api\node_modules\#aws-lambda-powertools\tracer\src\Tracer.ts:364:33)
at Object.<anonymous> (C:\Users\<user>\Documents\Projecten\stations-api\app\get-guiding-lines-combinations.test.ts:41:41)
at Promise.then.completed (C:\Users\<user>\Documents\Projecten\stations-api\node_modules\jest-circus\build\utils.js:391:28)
at new Promise (<anonymous>)
at callAsyncCircusFn (C:\Users\<user>\Documents\Projecten\stations-api\node_modules\jest-circus\build\utils.js:316:10)
The way I import my custom class:
import {
BadRequestException,
Exception,
InternalServerException,
NotFoundException,
} from '../models/Exceptions';
The custom class itself:
export class InternalServerException implements Error {
message: string;
name: string = 'InternalServer';
statusCode: number = 500;
constructor(message?: string) {
this.message = message ?? 'Internal server exception';
}
createResponse(): APIGatewayProxyStructuredResultV2 {
return {
statusCode: this.statusCode,
body: this.message,
};
}
}
While it can easely find my custom classes etc when running the tests. How can I get my classes recognized inside the evaluate window? Since this makes debugging a lot easier. (The version I am using is Intellij Idea 2022.3.2 ultimate)
I have two modules in one folder, mod1.js:
'use strict';
export class MyClass {
constructor() {
}
lala() {
alert(1);
}
}
And mod2.js:
'use strict';
import {MyClass} from './mod1';
let c = new MyClass();
c.lala2(); //HERE I WANT TO SEE ERROR
The problem is that Visual Studio Code doesn't show error in mod2. How to make it show the error, if it is possible?
The following code is generated in bundle.js.
Internet Explorer states there's a syntax error for class and that is correct.
Why is this in my bundle.js and how can I fix this?
let Screen = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_1_mobx_react__["observer"])
(_class = class Screen extends __WEBPACK_IMPORTED_MODULE_0_react__["Component"] {
componentDidMount() {
if (this.componentWillRender) {
this.componentWillRender(this.props);
}
}
}) || _class;
SCRIPT0001: Syntax error
bundle.js (12470,99)
I have a Typescript project, which calls a function from a module.js module. Here is my initial code:
//app.ts
import { MobileServiceUser, setCache, getCache } from "nativescript-azure-mobile-apps/user";
export function onLoginTap(args) {
console.log("tap");
ai.busy = true;
var cache = getCache();
}
if I use the VSCode "go to definition" feature, then getCache() goes to the import statement at the top, if I do this again, then I go to:
//module.ts
declare module "nativescript-azure-mobile-apps/user" {
export class MobileServiceUser {
mAuthenticationToken: string;
mUserId: string;
constructor(o: { userId: string; });
}
export function setCache(user: MobileServiceUser): void;
export function getCache(): MobileServiceUser;
}
When I execute the code and the var cache = user_1.getCache(); line is executed, my app crashes, throwing error:
TypeError: user_1.getCache is not a function
File: "/data/data/inc.tangra.azuremobileservicessample/files/app/main-page.js, line: 94, column: 23
app.ts looks like this compiled to js:
var user_1 = require("nativescript-azure-mobile-apps/user");
function onLoginTap(args) {
console.log("tap");
ai.busy = true;
var cache = user_1.getCache();
}
Why isn't the code recognising the imported function?
Update: this repo shows the project structure (the first page of code is in sample/main-page.ts
I am implementing a simple angular application with typescript. I pass a service reference to a controller, but when I try to invoke a service's method I get an exception saying the service reference is undefined. The "dataAccessLayer" module is correctly added as dependency in "clinicManager" module (the one to which the controller belongs)
My service:
module app.dal{
interface IDataAccessService{
get(id:number):app.Model.IPatient;
}
export class DataAccessService implements IDataAccessService{
private _db : Loki;
static $inject = ['Loki'];
constructor(private Loki:Loki) {
this._db = new Loki('./database/db.json',{
autosave: true,
autosaveInterval : 3000 // 3 secs
});
}
get(id:number):app.Model.IPatient {
// Implementation here...
}
}
angular.module('dataAccessLayer',['lokijs'])
.service('dataAccessService',['Loki',DataAccessService]);
}
The controller:
module app.PatientDetails{
interface IPatientDetails{
patient: app.Model.IPatient;
}
import accessLayer = app.dal.DataAccessService;
export class PatientDetailsCtrl implements IPatientDetails{
private dataAccessService: accessLayer;
static $inject = ['patient','dataAccessService'];
constructor(public patient:app.Model.IPatient, dataAccessService:accessLayer){
this.dataAccessService = dataAccessService;
// -> TypeError: Cannot read property 'get' of undefined
var patient = dataAccessService.get(1);
}
}
angular.module('clinicManager')
.controller('patientDetailsCtrl',['dataAccessService',PatientDetailsCtrl]);
}
app.js
angular.module('clinicManager',['ngMaterial','dataAccessLayer']);
index.html
<!-- Application scripts-->
<script src="app.js"></script>
<!-- Services-->
<script src="DataAccessLayer/DataAccessService.js"></script>
<!-- Controllers-->
<script src="Controllers/PatientDetailsCtrl.js"></script>
The service gets properly instantiated if I remove the reference to Patient in the controller, the service works fine. I put the code here to better show the formatting:
module app.PatientDetails{
interface IPatientDetails{
// patient: app.Model.IPatient;
}
import accessLayer = app.dal.DataAccessService;
export class PatientDetailsCtrl implements IPatientDetails{
private dataAccessService: accessLayer;
static $inject = [/*'patient',*/'dataAccessService'];
constructor(/*public patient:app.Model.IPatient,*/ dataAccessService:accessLayer){
this.dataAccessService = dataAccessService;
// The function is now called properly
var patient = dataAccessService.get(1);
}
}
angular.module('clinicManager')
.controller('patientDetailsCtrl', ['dataAccessService',PatientDetailsCtrl]);
}