388
questions
4
votes
4
answers
210
views
Check type of a function parameter
Since TypeScript is a superset of Javascript and 'Type' would be removed in the resulting js files, so I guess playing with 'type' would not work like this, right?
Also, is there any better way to do ...
0
votes
1
answer
78
views
Postponing .then() calls on a Promise returned from an async JavaScript function until after multiple awaits have run inside the function
I am using an asynchronous JavaScript http client to download & process some paged JSON data from an initial URI & subsequent page URIs.
Each JSON page includes the URI for the next page, if ...
0
votes
1
answer
425
views
how ES7 import module's object in Node.js
var GoogleStrategy = require('passport-google-oauth20').Strategy;
How can I use ES2017's way to write it? I try
import GoogleStrategy from ('passport-google-oauth20').Strategy
But it couldn't work
...
1
vote
1
answer
970
views
Jest Module Mock with ECMAScript Modules
Using the documentation (https://jestjs.io/docs/ecmascript-modules) as a guide, I have written the following:
package.json:
{
"scripts": {
"watch-test": "jest ./test --...
0
votes
0
answers
781
views
How to upgrade es2017 to es2020 without upgrading angular version?
I want to upgrade es2017 to es2020, but I don't want to upgrade angular version. Is it possible? My angular version is 5.2.
1
vote
1
answer
1k
views
How to throw "expressive" / console friendly exceptions in JavaScript?
JavaScript noob here... I'm exploring various options for throwing exceptions.
Throwing a string / primitive value
This seems to be bad practice for several reasons (catching, stacktrace, ...)
Using ...
-4
votes
1
answer
135
views
How can I sum object values by array data using ES standard? [closed]
I have an array of objects. Each object has a "tag" property with an array list. The values in this list repeat from object to object. I would like to sum up "cost" and "...
1
vote
1
answer
789
views
Extra execution context in async functions
When I was reading spec I saw next part:
NOTE: Copying the execution state is required for AsyncBlockStart to resume its execution. It is ill-defined to resume a currently
executing context.
I don't ...
0
votes
2
answers
156
views
ECMAScript 8, async await, syntactical errors javascript
using more then one async() in a chain in the function breaks my function.
Is there a way i can include Key2pkcs8() inside generateKey() ?
async function generateKey() {
let getKeyPair = await ...
0
votes
0
answers
65
views
How to determine the goal symbol when tokenize ECMAScript in lexical grammar
I'm writing a JS macro preprocessor, and refer to the ECMA-262 specification for some guide to parse js code.
I use the code parser to determine where to do macro replace in a standard/precise way, ...
0
votes
3
answers
151
views
How to find repeated values and store repeated values into new array in javascript
I am trying to implement a logic where I have an array [3,4,63,5,5,1,5,2,63,2,4,5,6,2,4,56,74,2,671,1,4,5,7,3,6] . I want to find all repeated elements and I want to store these all repeated elements ...
-1
votes
1
answer
30
views
Confused about this & getcontext js/ts and how to get around it
So, i have a problem where i'm constantly running into undifined errors, (in browser) and seemingly can't figure out why / how to get around it. From what i've gathered is that the keyword "this&...
2
votes
1
answer
2k
views
How to support top-level awaits in typescript?
I'm using version 4.3.5 of typescript with Ionic and have ts(1378) error.
Here are is the tsconfig:
{
"compilerOptions": {
"target": "es2017",
"lib": [...
0
votes
1
answer
2k
views
How to make a separate a sync function wait for another async function?
I am unable to callback async function inside of another async function.
I am receiving this in the console:
Promise {<pending>}
__proto__: Promise
[[PromiseState]]: "fulfilled"
[[...
0
votes
1
answer
148
views
Transform/map json to another format
Have long JSON object and small part is below:
const valueObject = {zipCode: 12345, street1: 'street 1', street2: 'street 2',city:'cityname', uniqueNum: '123456789'};
const mappingObject = {address: {...
0
votes
1
answer
38
views
TypeError: Cannot read property 'onMouse' of undefined React Class Component
I want to do when the user clicks on Input Element and the button element in the form will change to Send icon from the microphone icon. My idea was to get the value from onClick or mouseEnter ...
0
votes
1
answer
492
views
Why does Number.parseInt('111AAA') works like its supposed to in JS ? What is the reasoning behind this behaviour?
If I execute parseInt('111AAA') we get the output '111'. In javascript why does parseInt work as its mentioned in the MDN docs.
The parseInt function converts its first argument to a string, parses
...
0
votes
1
answer
127
views
es6/7 shorthand for assigning properties from object to HTMLElement
What would be a shorthand for the following:
setupIframeConfig(element: HTMLIFrameElement, config: IFrameConfig){
element.src = config.src;
element.width = config.width;
element.width = ...
0
votes
2
answers
3k
views
ES2017 NEST JS @IsEmpty Unable to resolve signature of property decorator when called as an expression.This expression is not callable. is not empty
Hi people im newer with Nest JS and i trying to add dto validator but for example when i tried to add isNotEmpty or Max compiler show me this error:
Unable to resolve signature of property decorator ...
1
vote
1
answer
1k
views
Typescript `esModuleInterop` ignored with module import
I'm trying to import this module into my Typescript file but it is throwing an error about how the module is imported. This is a Google Firebase Function script but I am importing this module in other ...
2
votes
8
answers
258
views
What's the shortest way to copy only selected attributes in JavaScript?
Given the following two objects:
let a = { foo: 'bar' };
let b = {
one: 1,
two: 2,
three: 3,
four: 4,
five: 5,
six: 6,
seven: 7
};
We can assume that all values within these objects ...
-1
votes
1
answer
1k
views
apply arrow function as object property in typescript
I have following code and wondering if I can apply as arrow function on line data({value}: {value: string}) {return func(value); },
function func(value: string){
return `${value} has been formated`...
2
votes
1
answer
170
views
Regex - find all words starting with $_ that fall anywhere between template strings
Can I solve the following with a single regex? I know it can be done with two separate regex, but I'm curious if it can be done with just one instead?
Find all instances of words (variables) that ...
0
votes
2
answers
161
views
Turn callback to promise and using of `await`
I've found this sample snippets in this article :
<script>
async function get_data() { // async function
await $.get('https://url.com/one')
await $.get('https://url.com/two')
...
1
vote
1
answer
1k
views
JavaScript modules - dynamic imports and side effects
Can anyone tell me precisely what is meant by the following, from MDN docs for import() (emphasis mine):
The following are some reasons why you might need to use dynamic import: ... When the module ...
1
vote
1
answer
258
views
ESLint complaints with "Unexpected token" on class async method
Given this class :
class Foo {
async bar() {
}
}
ESLint says that bar is an unexpected token. My .eslintrc file is this :
{
"env": {
"browser": true,
&...
1
vote
3
answers
392
views
How do I chain return values from async functions in ES 2017?
I'm trying to do this:
service.getConfig()
.then(cfg => service.getData())
.then(data => service.process(data,cfg))
.then(results => console.log(results))
.catch(err => console.log(err));
...
1
vote
1
answer
211
views
Return Promise in async function in JavaScript (es2017) [duplicate]
I'm wondering if there is any semantic difference between the 2 functions below in ES2017 or later:
async function returnBool() {
const promise = new Promise(((res, rej) => {
setTimeout(...
76
votes
2
answers
56k
views
ES7, ES8, ES9, ES10, ES11 Browser support
Regarding compatibility between ECMAScript specification and actual implementation;
It is fairly easy to check out the data about browser support for ECMAScript2015 (ES6), but I found it pretty ...
3
votes
2
answers
137
views
Count Array Items in Object of Arrays (combined count)
Consider the following object:
const test = {
foo: ['foo', 'bar', 'foobar'],
bar: ['foo', 'bar', 'foobar']
foobar: ['foo', 'bar', 'foobar']
};
How would one go about getting the combined ...
0
votes
0
answers
51
views
Resource of the recommended and modern EcmaScript commands?
I am in the process of learning JS/ES, and to see if I have understood OOP correctly, would I for each of OOP code snippets in my text book, like to write the same as non OOP, to see if I have ...
1
vote
1
answer
116
views
Why do functions seem to be objects?
I am trying to learn JS/ES and am a bit confused about classes and objects.
The two code snippets below do exactly the same, but the last one is clearly using a class. But what is the first using? I ...
0
votes
2
answers
668
views
How to serialize an object and cast it back to the same class as the original object
I'm new to JavaScript so bear with me if what I'm asking is not "how you do it in JavaScript". Advice on other approaches are welcome.
I have a class named State and I need need to serialize objects ...
1
vote
1
answer
768
views
Listening for a boolean change with Javascript/jquery (Proxy object)
Javascript Proxy not triggering. I am triying to trigger some functionality after 10 seconds. But after 10 seconds, when I update the variable "dezSecondsNaPagina" nothing happens.
var ...
0
votes
1
answer
111
views
ECMAScript 2017 concurrent async functions with possibility to wait for subpromises that should not be concurrent?
Suppose we have multiple concurrent tasks that each does at least one web request at one point or another and they take a while to complete. Suppose they also may or may not at some arbitrary point in ...
3
votes
1
answer
1k
views
Is the following a proper way to write long computations in JavaScript that needs to run on a browser?
I am trying to use async / await to do long computations on JavaScript on a browser. Should the code be changed or any improvements be done? It seems using promises may make it complicated. I also ...
0
votes
2
answers
310
views
react native code works inline but not when imported
The following code works properly in react native 0.61.5.
// userApplication/screens/UserScreen.js
import React, {Component} from 'react';
import { Button } from "./../components/arComponents";
...
0
votes
1
answer
996
views
Is there a way to jump to specific line?
How to skip "First Message" or to start async function from n'th line?
async function oneByOne() {
await talk("First Message");
await talk("Second Message?");
await talk("Last Message?");
}
2
votes
2
answers
1k
views
Is there any way for Eclipse to handle async await (ES2017) in JavaScript without errors?
I have tried Wild Web Plugin and it still shows "Semi-colon expected" at the codes that use async.
Wild Web Plugin claims that it handles ES2018 (https://marketplace.eclipse.org/content/wild-web-...
-3
votes
1
answer
222
views
Read Async Object Set Using Await
A global object has its key/value (thing) is set in an async function setter(); using await. How to asynchronously read the value of thing in another async function getter();?
I'm getting undefined ...
1
vote
1
answer
2k
views
How to get value from Axios request?
I have this code
(Pay attention to the HTML class 'symbolTicket "')
<template>
<div class="chart">
<span class="symbolTicket">
{{getTicket()}}
</span&...
2
votes
5
answers
479
views
Angular 8 Native Typescript crash-free, accessor shorthand
Angular 8 :
I used to use as a short hack on typescript side :
object['accessor']['accessor']['accessor']
to get
object.accessor.accessor.accessor
without running the risk of throwing an error ...
0
votes
2
answers
400
views
Make await return thenable, or infinite recursion in awaiting awaitable
Trying to come up with API, mixing in promise functionality like:
class Awaitable {
constructor () {
this.promise = Promise.resolve()
}
then (fn) {
// awaited result must be _this_ ...
-2
votes
1
answer
306
views
How to use aynsc/await in javascript for returning objects from asynchronous operations
I cannot for the life of me figure out why async/await behaves the way it does.
Consider this example.
I want a function that does some db initialization, and returns me the database object when it ...
1
vote
0
answers
140
views
Will using es2017 as a lib in my tsconfig but having es5 as my target render my code incompatible with IE11?
My code needs to be able to support IE11 at the minimum, which renders most ES6+ modules incompatible. I've set the target in my tsconfig to es5, however I wanted to use es2017 modules in my code. ...
0
votes
0
answers
38
views
How to stop executing map function on array index 5 in javascript [duplicate]
I have array of 10 elements, I am mapping to extract array data . I want to stop array executing when compile reached to array index 5 . I know it possible with for loop but I need it in map function. ...
1
vote
0
answers
339
views
Tableau WDC and Javascript promises
I'm (trying to) building a Tableau Web Data Connector (WDC) which needs to hit an external API and run a bunch of requests that are dependant on each other. However, I'm hitting a problem with ...
2
votes
0
answers
2k
views
Error Gulp Build: async functions is only available in es8 (use esversion 8)
When I'm going to compile my code with gulp
displays the following error (image highlighted).
It follows the function of the 1685 line that uses async in angular cli.
$scope.GetNomePacienteIndicou = ...
3
votes
2
answers
633
views
How to get Javascript's IMPORT EXPORT working. Do I need transpiler?
I am so confused about this. All I want to do is simply break up my javascript into modules, and include them in certain pages. Some pages may need my user-module.js , some pages may not.
I have ...
3
votes
2
answers
2k
views
javascript await on multiple chained async functions
Say I have the following:
const a = new A();
await a.getB().action();
A.prototype.getB() is async as-well as B.prototype.action().
If I try to await on the chaining of the functions I get an error:
...