Questions tagged [typescript]

TypeScript is a typed superset of JavaScript created by Microsoft that adds optional types, classes, interfaces, async/await, and many other features, and compiles to plain JavaScript. This tag is for questions specific to TypeScript. It is not used for general JavaScript questions.

Filter by
Sorted by
Tagged with
0
votes
0answers
2 views

How to use typescript reflection in my case?

I`m trying to make a game MVC library in typescript. My language is typescript and I struggle with reflection and decorators. Also I playing a lot with Nestjs and I like that style of decorating. I ...
-1
votes
0answers
7 views

How to type a property on a function with typescript?

I'd like to have a *.d.ts file along with the following code. But I can't figure out how to do it. let state = undefined const Store = (init) => { state = init; } Store.setAllToState = (obj) =&...
-1
votes
0answers
13 views

Null-conditional operator in javascript? [duplicate]

Note: Null Conditional Operator is different than Null Coalescing Is there a "null coalescing" operator in JavaScript? In python, c# we have Null Conditonal Operator ?. we still lack ...
0
votes
0answers
14 views

Modifying Property Values in Typescript Decorator

I have class level variable in an Angular Service. I need to prepend some value to the variables value via decorators. How can I achieve? @Injectable() export class ServiceName{ @Service(...
0
votes
2answers
16 views

Jest mock timers not working as expected asynchronously; how to make this test pass?

I am trying to test a queuing component that makes calls and handles a lot of scheduling. I want to test it with a mock api where the api responses are delayed as they would be in real life, but I ...
0
votes
0answers
6 views

Use eslint with @typescript-eslint/parser, but the typescript rules not work

I want to use eslint and @typescript-eslint/parser to test my ts code, but got none errors of typescript rules. .eslintrc { "parser": "@typescript-eslint/parser", "plugins": ["@typescript-eslint"...
0
votes
1answer
35 views

Confused about the fallback route in Angular

I tried to update myself to Angular 8 by reading the Angular docs again. I want to create navigation rules like. by default, enter the index page, redirect to /home, mount to homemodule. there is ...
0
votes
0answers
27 views

Conditional type in TypeScript and recursion

I'm trying to define a type that is a modification of another unknown arbitrary object. Sort of dependent type I guess. For example: If type A is: type A = { one: string, two: { inner: ...
0
votes
0answers
8 views

Able to ping exact endpoint from browser that I can't from subscribable

I have a microservice that I have successfully tested that is returning a json from url/uri: http://localhost:8090/api/v1/movie/search?title=The%20Arrival%20of%20a%20Train%20(1896)&year=1896 I ...
0
votes
0answers
9 views

Lint alphabetical order for all declarations in a file

I am looking to do some sort of lint / style check / fix to see if a given file's functions are in a given arbitrary order in the file. Ideally given this: const b = 'a' const a = 'a' It would ...
0
votes
1answer
20 views

Do Angular Reactive Form Validator.min/max check Perform Type Conversions before checking the value?

Preface: Part of the reason why I'm asking the below questions is that when I do form.value.purchaseCost without having type=number on the <input> field, I get a string. I had to do a manual ...
1
vote
1answer
26 views

Implementing Either Monad in Typescript

I've been experimenting with TypeScript lately, and I'm trying to implement some basic monads. I've already got a reasonably functioning Maybe (with the same methods of my Either below, at least), but ...
0
votes
0answers
10 views

how to get the classes in the loaded library

1) In this answer script tag is added and the library is loaded during run time /a/42766146/8577819 2) Here (/a/47236978/8577819) it is shown how to ...
0
votes
0answers
36 views

How to do dynamic import in typescript based on file from endpoint/url

Files in Server // "/local_folder/classesfolder/testclass_file.ts" not part of build export class testclass { public ds() { console.log("inside test class"); } } // "/local_folder/...
0
votes
0answers
14 views

Passing a prop through a file to the main one

The title may not seem that logical, but through this post you will know my issue. Well, I got 3 files and I'm trying to pass a prop from a file which contains the CSS attributes of a component to ...
0
votes
0answers
14 views

Automatically stringifying object when inserting to a MySQL JSON column with knex

Straight to example code: create table test_json_table ( data json not null ); I can insert to the table like this: const columns = { data: "{ some_json: 123 }" }; // notice that the data ...
0
votes
0answers
8 views

Stencil JS not working with non-default imports

I'm using BabylonJS in a StencilJS app, and I can only seem to import in a very specific way. For instance I can't do: import { Engine, Scene } from "babylonjs"; It says 'Engine' is not exported ...
0
votes
0answers
7 views

Mocha - Requiring Custom Modules

Working on a project in VSCode/node, and struggling hard to get mocha to recognize my internal typescript module, as it always reports that it cannot find it. My project structure is basically: |...
-1
votes
1answer
34 views

Move data between classes and then iterate through the new class from the html page

The Setup I have an angular 7 app that gets data from a web api in the form of JSON. As the app stands now it works but I think I am making too many API calls and I think I can reduce them to 1. ...
0
votes
1answer
25 views

Type a class so that all methods match enum

I have a Pages enum here and I'd like to type the class methods, so that they match the enum. How can I achieve this? enum Pages { accessLogout = 'access.logout', accessLogin = 'access.login' } ...
1
vote
1answer
40 views

Why can't I check if an environment variable is undefined?

This test is printing out fine!!!!. Why isn't it printing out UNDEFINED!!!!? describe('process test', () => { require('dotenv').config() it('will make a call from the athena library to ...
0
votes
1answer
30 views

How to return value in component react typescript

I'm trying to return a value out of a component. Basically what it needs to do is just not being displayed if its turned on {false}. firstfile.tsx export default (isDisplayedLoadingTitle: IProps) =&...
0
votes
0answers
8 views

Add items to ngx-chips input model and only keep display and value fields

I'm using ngx-chips for a tag input control. I'm using my own custom objects as items to use in the control's dropdown; these have this structure: _id: number; name: string; summary: string; ...
-4
votes
5answers
41 views

Is there a native way to “chain” / pass-through functions? [on hold]

I am looking for a way to pass payload to / through the plusOne function and return 'the number is 2'. I have a simple "chain" function to issue a callback const chain = (value, callback) => ...
0
votes
0answers
20 views

Working around unset “length” property on partial functions created with lodash's partialRight

I'm working with MomentTimezone for time manipulation in the browser. I am using TypeScript and Lodash too. I have some accountTimezone set on the window containing the authenticated user's ...
1
vote
2answers
32 views

property does not exists on type Object from subscribe

Im using a forkJoin to do multiple http calls but it give me the error error TS2339: Property 'data' does not exist on type 'Object' forkJoin(this.userservice.getUser(), this.userservice....
0
votes
1answer
25 views

Replace nested promise.all with observable stream to aggregate over an array

In an Angular app we have a method which merges 3 api results in a single giant list. loadPlaces$ = this.actions$.pipe( ofType(PlaceActionTypes.LOAD_PLACES), switchMap((action: LoadPlaces) =&...
1
vote
2answers
47 views

Need help in Javascript to create an array of objects

Below is my problem on creating array of objects using Javascript. I am getting error message with new lines added as below where i need to split the messages and collect row numbers. The row numbers ...
-2
votes
1answer
58 views

Why is a property not recognized when looping through a list?

The Setup I have a class called myClass: export class myClass { name: string; age: number; city: string; } and I have another class called people: export class people { name: ...
-3
votes
1answer
30 views

How to make a http synchronous call [on hold]

What missing code am I missing in order to make a http synchronous call to the variable test2? I'm NOT interested in making a http asynchronous call. In console log I retrieve message "...
0
votes
1answer
15 views

Property 'title' does not exist on type 'IntrinsicAttributes & IProps'

there. I'm trying to make an item not visible in another view, I'm working this out with interfaces. The problem is that I'm getting the error which is in the title of this question. Here is part ...
1
vote
1answer
26 views

Is it recommended to publish source files for TypeScript node modules?

I noticed some TypeScript node modules (e.g loopback-next/packages) publish their source files with the node module. Is there a particular reason for this or is it just unnecessarily increasing the ...
0
votes
0answers
14 views

How to add HTMLDocument Element to a JSX Template for a StencilJS Component

Newbie question in StencilJS v1.0.7 here. I am trying to add a HTMLElement to a JSX Template, that get's return and render by StencilJS. But not getting any wanted result. I am not sure if this a ...
1
vote
1answer
24 views

How to get private methods working in TypeScript?

I have some code that looks roughly like: class A { #hidden = 0; method() { return this.#hidden; } } This works fine when I use JS, but when I convert it to TS I get the error Parsing ...
0
votes
0answers
18 views

Convert callbacks to observable rxjs

I wanna create an Interceptor of nestjs and on this level and want to do uploading file. I can't find a solution, how to resolve this code by Observable (https://github.com/fastify/fastify-multipart) ...
0
votes
0answers
35 views

RxJS - Resume function when observable updated

I have a function: handleGroupingIntentWithoutAssignment(masterTable: Table, tableToAdd: Table, station: Station) { //I show the Modal via a GuiState service: this.guistateService....
0
votes
3answers
37 views

Filter throws - Cannot read property 'toLowerCase' of null

I am trying to filter on the given input against the cached query result. Since I am filtering again user input value and database , I am converting them in to lower case and checking result = this....
0
votes
0answers
28 views

How can I run a Typescript API in a Javascript repository?

I am trying to configure one launch.json file that is able to hold configurations to run/debug 2 APIs (one is Javascript, the other is Typescript). The Javascript API runs fine. The Typescript API ...
0
votes
1answer
31 views

TypeScript: Return same type as parameter

formatISODate function expects string value. There are many strings which I need to convert if not undefined. I could do as follows: { date1: date1 ? formatISODate(date1) : undefined, date2: ...
2
votes
1answer
34 views

regex to match only alphanumeric, hyphen, underscore, and period, with no repeating punctuation

I'm new to regex, and typescript, and trying to get a regex to match: 1. must start with alphanumeric (repeating is fine) 2. can contain alphanumeric (repeating is fine) 3. can contain periods, ...
0
votes
1answer
21 views

How to make some fields in object required

I need an interface for making some fields of other interface as required. For example: I have IUserInterface: interface IUser { name: string; role?: string; } interface IUserFromDB { id: ...
0
votes
0answers
19 views

Exporting “mixed” declarations from .d.ts file - Typescript

I've got a Typescript project with a .ts file that is exporting some interfaces and a class. Similar to this: export interface Tree { value: string, anotherValue: number, children: Tree[] } ...
2
votes
2answers
30 views

TypeScript loop over array of tuples

How do I loop over an array of tuples in TypeScript? e.g. for (const [x, y] of [['a', 1], ['b', 2]]) { y + 1; } complains: error TS2365: Operator '+' cannot be applied to types 'string | number' ...
-2
votes
1answer
39 views

How to pass data to component to another component [duplicate]

I need help, at the last days I was tring to pass data between components... I followed alot of samples around internet, and none of those works. The most tutorials says to me to use @input and @...
0
votes
2answers
61 views

String inside {{ }} as Interpolation Code

The FormControlNames of my elements are generated dynamicly this way: id{{foo.foo_id}}{{bar.bar_id}}{{bob.bob_id}} The result is something like id137. When I now use {{form.controls.id137.status}}, ...
1
vote
1answer
41 views

angular 8 - component not loading in the html

I was wondering if anyone had a similar issue like what Im having now? I was following the angular course on Scrimba, its lecture 7, angular component. I created the angular app using cli command ...
2
votes
1answer
32 views

Why Electron spawns a process per each window?

I'm working on electron app with multiple windows. Let say I have the main one and a few child windows. If I create 20 child windows with google.com open from the main process it spawns around 23 ...
0
votes
0answers
17 views

Add Color Scheme JSON list to Sass file in Angular 8 Environment

I'm building a Web based project with Angular 8. At the starting of the Application, I need to retrieve a list of predefined colour scheme defined in a JSON file and I have to add them dynamically to ...
1
vote
0answers
24 views

Typescript bug? Correctly typed array method with “Parameter 'x' implicitly has an 'any' type” error

I'm mapping over an array called matches with the type signature Match[], and I've got noImplicitAny set to true. Given this code: matches.find(m => !m.foo) I would expect Typescript to infer ...
0
votes
1answer
19 views

How to fix “Initializer provides no value for this binding element and the binding element has no default value.” in TypeScript?

I am migrating Apollo GraphQL API project written in JavaScript to TypeScript. And I am having an error at finding a user code block, saying that var idArg: any Initializer provides no value for this ...