We’re rewarding the question askers & reputations are being recalculated! Read more.

Questions tagged [typescript]

TypeScript is a statically typed superset of JavaScript created by Microsoft that adds optional types, classes, interfaces, enums, generics, 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
1
vote
0answers
24 views

Object.assign({}, inputObj) resulting in empty object [duplicate]

I'm trying to clone properties of an object using Object.assign: export function result<T>(type:string, payload?:T&{requestParams:any}){ const actualPayload = Object.assign({}, payload);...
1
vote
0answers
19 views

Type for an item in React component map

I spent some time on searching an answer on stackoverflow and haven't found something so far, so I decided to ask. I currently have a map with 2 items (Tables) potentially it can be more, where a ...
0
votes
2answers
55 views

Cannot understand the Typescript syntax

I am new to typescript and need help in understanding some code. code : addSilentCallBackHandler(): void { this.mgr.signinSilentCallback().then(callback()); } function callback(): (...
-1
votes
0answers
25 views

how to split the multiple values in an angular form into unique list

hey folks I have an angular form with a box that populates <john f Kennedy><Adam Ronald,Kenny filler, Andy Rower><Kenneth Manichean,Ryan Lewis,Adam Ronald><Fay Graham>. ...
0
votes
0answers
7 views

How does customFormatErrorFn create error in graphql express

So I recently started with typescript and migrating my existing JS code. Can someone explain me the working of this code? i.e how would this execute in steps. So In graphQl-express, to handle ...
0
votes
0answers
22 views

Reverse function strange behaviour when scroll

I have this typescript code : get history() { return this.isCollapsed ? this.service.history.reverse().slice(0, this.SHOW) : this.service.history.reverse(); } In template : <...
-1
votes
1answer
16 views

Concatenate text from React Hook

I have following hook: const [textToFront, setTextToFront] = useState(''); When I call setTextToFront I see that old state was cleared, I want to implement simple thing, I just want to create one ...
0
votes
0answers
9 views

Check instanceof generic type in typescript(ionic) to assign a variable

in TypeScript I have a generic type in a class export class Favoris { Document: Document = null; ... } export class Document{ ... } export class Form extends Document{ Fields: any[]...
1
vote
1answer
24 views

Error 415 Unsupported Media Type in uploading files

I am aware that there is already a similar question, but it didn't solve the above error. This is my PUT action in my API's Controller and this is working fine in Swagger: [HttpPut("{id}/upload")] ...
0
votes
0answers
10 views

How to proceed validation without creating a new DTO (Data Transfer Object) in Plumier

I create a registration form contains password confirmation which is not part of the domain model. I don't want to make an extra DTO to just to make the validation work. My domain model is like ...
0
votes
0answers
24 views

Jasmine testing: Expected undefined to equal Object. (How to test @input)

I have troubles with that error. I think i forgot something and cant figure out what is it. The task is simple: just test my simple component. Here we go: import { Component, OnInit, Input } from '@...
-1
votes
0answers
32 views

Using promises in Typescript instead of setTimeOut

I'm refactoring a function that uses a setTimeOut to a more cleaner way. I'm trying to implement promises now, but it doesn't work 100% My code before filterError(){ this.search = "error" ...
2
votes
2answers
24 views

Binding select tag data to reactive form in Angular

I've a JSON formatted data coming from back-end, with gender as a select tag in front-end I'm unable to pre-select the option that comes with json data. Also from back-end it comes in enum format and ...
0
votes
0answers
17 views

Type tuple so that function chain has valid parameter and return types

I'd like to create a type for this tuple / array below. Where this is valid: const funcs = [(a: string) => 1, (a: number) => 'A', (a: string) => 2] And this is invalid: const funcs = [(a: ...
-1
votes
1answer
36 views

Google Books API Rate Limit Exceeded

With this demo I get rate limit exceeded from the Google Books API: https://angular-temp-slice-demo.stackblitz.io/books To see it open the developer console in chrome and then do some searches. The ...
1
vote
1answer
33 views

Close dropdown with button - Angular Material

I am using the selectTo dropdown in angular material design. This is my code: <mat-form-field id="inputClick" appearance="outline" (click)="Valid()"> <mat-label>{{'GENERAL.TITLE' | ...
0
votes
0answers
10 views

Property 'status' does not exist on type 'GraphQLError'

I still trying to comprehend to typescript and moving my JS code typescript code. In JS, I had something like this graphEndpointHandler(graphSchema) { return (req: Request, res:Response) =&...
0
votes
0answers
15 views

Angular Table with expandable rows, subscribe and get data on expand row

I have requirement of getting data over http upon expanding the row of mat-table because of the data size. I have tried multiple solutions and nothing seems to work. Would be glad if someone could ...
0
votes
2answers
52 views

How to know date before it expire

I have a question with knowing expiring date from the list. In example i have a few list that contains some date data. What if i have expireDate: 2019/11/20 then i will notice that date from 7 days ...
0
votes
1answer
50 views

What is the different of using =, =>, : in react? [duplicate]

I'm a bit new to react. I can use them with my past experiences. For example, I need sth to describe, I found a similar declaration and use the same shape. But I would like to learn the fundamentals. ...
0
votes
0answers
12 views

How to Show Spinner in Number on Every HTTP Request and HTTP Response in angular 6 with typescript

I am Implementing Show Spinner on Every HTTP Request and HTTP Response on every API Call now i want to show spinner in number that means how much response is done and i want to calculate that response ...
2
votes
3answers
36 views

Understanding type asseration

I am just starting with typescript and as much as i thought things are going to be easy, typescript doesn't seem to be that similar to javascript and kinda confusing Anyway, In typescript (Not sure ...
2
votes
2answers
30 views

why the keyof word in TypeScript behaves different in 2 `type defination`s?

why the res1 can't know its type is number as the res2 does? interface P { name: string; age: number; } const people: P = { age: 30, name: 'Peter', }; type T = keyof P type Fn1 = (p: P, t: T)...
0
votes
0answers
17 views

Most efficient way to constrain parameter type based on another parameter

I have a list of car brands, I have a car factory that takes a car and an options object that differ depending on the brand. type CarBrand = 'mazda' | 'toyota' | 'hyundai'; export function ...
1
vote
3answers
56 views

pre selected dropdown in angular material

hi i using the angular material in angular 8 . i need to pre-selected option in dropdwown . i using this code : <mat-select *ngIf="justImage==true"> <mat-option selected (click)="...
0
votes
1answer
20 views

How are TypeScript generics different from Java?

The following code would produce the expected type error in Java, but TypeScript doesn't consider it an error. Is this by design, or is it a bug in TypeScript? abstract class UnitType<T extends ...
0
votes
0answers
12 views

Ascending and Descending sorting in Typescript on “Nov 04 2019, 12:07 PM IST” kind of date format

I am trying to automate one scenario with my Webdriverio and typescript framework. I picked the creation date of all the entries by below code: let allCreationDate : string = browser.element((.//*[@...
0
votes
0answers
10 views

Array with download urls from Firebase Storage won't recognize every entry

I'm currently trying to upload multiple images to Firebase Storage and store each download url inside of Firestore. FYI: images is an array of files So far, I've worked out this code: uploadImages(...
0
votes
0answers
18 views

How to import and use javascript node modules

In my code I am using javascript firebase module const FirebaseStore = require('connect-session-firebase')(session) What should be the correct way to import it and use it in typescript?
0
votes
1answer
16 views

Print origin Typescript Function Definition

As I understand, Javascript Function prototype has a method to print its own definition: toString() like below: function example() { // do something here } console.log(example.toString()); ...
2
votes
1answer
17 views

Server Pagination: Typescript Save GET method data to number

I need to implement a server pagination for a table where the data is taken from an SQL Database and i need to save the data from the response as a number(count:number) but if i check the totalItems ...
0
votes
1answer
51 views

Set key and value in dynamic angular form

This is my JSON: jsonData = { "event": { "params": { "behaviour": "behaviourValue", "message": "My Message", "severity": null } } } code ...
0
votes
1answer
25 views

D3.js V3 for angular 2+, fill style typescript error

I tried to implement this case on angular 6. But in the implementation, I encountered a problem.In the setting fill style, there is a error in typescripe. In change(data) function: I tried to add ...
0
votes
0answers
10 views

NGXS TypeError: Cannot read property 'getUploadState' of undefined:

i'm currently using NGXS to manage state in a big application, however i'm facing the issue in the title. a little overview is that i'm trying to use a Material modal all over the application using ...
0
votes
1answer
32 views

Angular 8: Validation With Condition Operator using equals expression

The following is an example of formControl name, with validation using dirty, invalid. I would like to add one condition, where MemberId should not equal -1. How would I add that into Formbuilder or ...
1
vote
0answers
21 views

Three.js + Angular: texture loading fails

Three.js renders a black scene because of texture loading. I am using three.js inside an angular component (angular version 8). I was trying to follow an old three.js tutorial on rendering Earth in ...
0
votes
0answers
10 views

Exporting types in an index file without namespace?

I'd like to export my library to be accessible under a namespace like: import myLib from 'my-lib' const value = new myLib.MyType() function foo(target: myLib.MyType) { } foo(value) Currently, I ...
0
votes
1answer
29 views

ngOnInit - Waiting for Observable Subscribe To Manipulate outcome Object

I am trying to get min / max validator in my template. ngOnInit() { this.app.object$.pipe(takeWhile(() => this.alive)).subscribe(object=> { this.object= object;}); this....
0
votes
0answers
20 views

Generics type narrowing [duplicate]

I'm having hard times trying to figure it out why the following does not work: type StringPropertyNames<T> = { [K in keyof T]: T[K] extends string ? K : never }[keyof T] function ...
0
votes
0answers
14 views

Mongo nested model referencing itself

I have a values schema that can reference itself so it can have many nested values attached to it. For example, here is an example JSON: { name: 'IPA', ...
0
votes
1answer
16 views

How to get assign return type from function generic

class Dyn { static flatten (a: any) { } static cliff <G extends any[], B, A extends (...a: G) => B, Z>(a: A, b: ( ) => Z) { return (...p: G) => { const ...
1
vote
0answers
29 views

How fix this typescript error: Property “nodename” doesn't exist

Line of code is readXML(): void { // testing the function let xmlstr = `<book><title>Some title</title> <description>some description </...
0
votes
0answers
21 views

Split one big abstract class into multiple ones + inherit from it

Basically, I have ONE main base abstract class that currently implements methods that will need to be split into different classes (getTestA1,getTestA2 need to be on one class and getTestB1,getTestB2 ...
2
votes
0answers
28 views

React Native calling actions in wrong order

I'm building a login form for my react native app. So there is a username field, a password field and a login button. I have a formReducer: const formReducer = (state, action) => { if (action....
0
votes
1answer
12 views

Assert exception details with JestJS

Question I set up the following Jest test to ensure an exception is thrown: it('can not rollback a step', async () => { await expect(app.service('rides').patch(ride._id, { currentStep: 1, ...
0
votes
1answer
23 views

TypeScript: Specify that an argument must contain a key matching another argument?

I am working on a library that works with linked lists. At the moment, it is hard-coded to accept a list node type that contains a "next" field pointing to the next node, of the same type, but I would ...
-1
votes
0answers
20 views

Stackblitz paints red squiggles that disappear on refresh?

While editing Stackblitz paints red squiggles under imports that are fine. For example in the below screenshot all I did was import the RouterModule like this and that caused the red squiggles. If I ...
0
votes
0answers
22 views

Cannot read property 'push' of undefined in typescript

I have been trying to figure out that how to insert list of into array and push new data into same array. collectionList: [any]; //Array defined collection: [ { Name:any, ...
0
votes
2answers
32 views

Angular 8: Validation errors without Repetition and simplified

Is there method to write Validation errors more elegantly and simple? Maybe way to write a shortcut method? Currently to do validation, it required long text below, <div class="form-group" [...
0
votes
0answers
6 views

What to do when @type/mongoose not implement method

In mongoose documentation I found useful method arrayOfSubdocuments.id. https://mongoosejs.com/docs/subdocs.html#finding-a-subdocument import { connect, Schema, model, Document } from 'mongoose'; ...