Lexical scoping in ES6 / Node

Issue I’m attempting to understand ES6 lexical scoping (using the node runtime). Consider the following: ‘use strict’; let x = 10; function f() { console.log(x); console.log(y); // This should crash } let y = 5; f(); Paraphrasing from the O’Reilly

Continue reading

how to call a function from template literal on ng-click

Issue I am calling a function close_popup from template literal. I want to pass a variable id. Below is the code function register_popup(id, name) { var htmlelement = `<div class=”popup-box chat-popup” id=”${id}”> <div class=”popup-head background-purple-gradient”> <div class=”popup-head-left”>${name}-${id}</div> <div class=”popup-head-right”> <span

Continue reading

URLSearchParams not accepting string

Issue const sortString = req.query.sort as string const params = Object.fromEntries(new URLSearchParams(sortString)) Now, when I go to implementation, I get: declare var URLSearchParams: { prototype: URLSearchParams; new(init?: string[][] | Record<string, string> | string | URLSearchParams): URLSearchParams; toString(): string; }; Now,

Continue reading

rewrite require to import statement

Issue I am trying to use https://www.npmjs.com/package/json-bigint with native BigInt support. In CommonJS I’d do: var JSONbigNative = require(‘json-bigint’)({ useNativeBigInt: true }); What is the ES6 syntax equivalent? This is not working: import * as JSONBigIntWrapper from ‘json-bigint’; const JSONBigInt

Continue reading

rewrite require to import statement

Issue I am trying to use https://www.npmjs.com/package/json-bigint with native BigInt support. In CommonJS I’d do: var JSONbigNative = require(‘json-bigint’)({ useNativeBigInt: true }); What is the ES6 syntax equivalent? This is not working: import * as JSONBigIntWrapper from ‘json-bigint’; const JSONBigInt

Continue reading

Argument of type 'string | undefined' is not assignable to parameter

Issue Why this code doesn’t work? const whitelist = [‘http://localhost:3000’ , ‘https://localhost:3443’, ‘http://localhost:4200′,’http://localhost:5000’]; const corsOptionsDelegate =(req: Request, callback: any) => { let corsOptions; console.log(‘origin’ + req.header(‘Origin’)); if(req.header(‘Origin’) != null){ if(whitelist.indexOf(req.header(‘Origin’)) !== -1){ console.log("index : " + whitelist.indexOf(req.header(‘Origin’))); corsOptions = {

Continue reading

Argument of type 'string | undefined' is not assignable to parameter

Issue Why this code doesn’t work? const whitelist = [‘http://localhost:3000’ , ‘https://localhost:3443’, ‘http://localhost:4200′,’http://localhost:5000’]; const corsOptionsDelegate =(req: Request, callback: any) => { let corsOptions; console.log(‘origin’ + req.header(‘Origin’)); if(req.header(‘Origin’) != null){ if(whitelist.indexOf(req.header(‘Origin’)) !== -1){ console.log("index : " + whitelist.indexOf(req.header(‘Origin’))); corsOptions = {

Continue reading

spread operator vs array.concat()

Issue What is the difference between spread operator and array.concat() let parts = [‘four’, ‘five’]; let numbers = [‘one’, ‘two’, ‘three’]; console.log([…numbers, …parts]); Array.concat() function let parts = [‘four’, ‘five’]; let numbers = [‘one’, ‘two’, ‘three’]; console.log(numbers.concat(parts)); Both results are

Continue reading

NgStyles inside NgFor in Angular 4

Issue I would like to change the font color depending on some conditions ==> both datas on comming back from observable returning by Http request, I try out theses codes bellow (Typescript+Angular) <td *ngFor=”let user of userService.users | async”>{{user.data.apps.details[0].label}} <span

Continue reading

Typescript transpile es6 .js dependency to es5

Issue I have a hypothetical Typescript file in my project (simplified example). Utils.ts: import * as HelperFromNodeModules from ‘helper-from-node-modules’; class Utils { static foo() { return HelperFromNodeModules.parse(…); } } Importing helper-from-node-modules consists of a Javascript file. helper-from-node-modules.js: const dep =

Continue reading