Questions tagged [typescript]

21866 questions
-2

votes
0

answer
38

Views

array in an array is not properly showing within my html

I am trying to make a breadcrumb component for angular7 but I can't get my array to properly show into my HTML and would like some tips because I can't find it on the internet. if you would be so kind as to help me I am still new to angular and can't think of a better way to make a breadcrumb compon...
Marc Roelse
0

votes
2

answer
25

Views

Variable data not retained to bind in HTML even after assigning data to it inside a subscribe() function

I have below app-product.ts code written as below: @Component({ selector: 'app-product', template: ` {{products.prod_name | uppercase}} Details Description: {{products.prod_desc}} ` }) export class ProductComponent { products:any = []; constructor(public rest: RestService){ this.getProducts() } getP...
Onera
2

votes
2

answer
29

Views

Assign Dynamic api reponse to typescript interface

I am new to typscript and nodejs. I am trying to assign a response get it from restful api call to typescript interface. I dont want to use Object.keys or Obejct.values to get the required data but trying to use typescirpt interface for that . Here is the response , // this is dynamic in nature {...
devmk
0

votes
0

answer
10

Views

Javascript to Typescript Migration: how to export types

actually i'm searching for a strategy to migrate our dojo 1.x projects from javascript to typescript. my idea was to do it step by step. so in the first step to rename all the .js files to .ts. by doing this minimal changes are needed to get a working typescript "class". example: my class "RequestMa...
wuhi
1

votes
1

answer
18

Views

Type assert uppercase interface to lower

In C# it is convention for class / interface properties to be uppercase. In ts & js this is not the case. So when we get data back from an ajax call it is normally uppercase. So I have something like the following where I want to type assert between the two: interface CSharp { B: string; A: string;...
Zze
1

votes
0

answer
12

Views

Jasmine trigger the search member function but can't get any response or error

I am new to Jasmine and I am testing via UI so after entering the values in the search input field and triggering keyup event the search function is called which I confirmed by logging at different points but the API call is not triggered which is inside the search function. Do I have to use await o...
Sohail
1

votes
0

answer
8

Views

Component cannot subscribe to event that is triggered from another component

I have a service. The communication provides via the service. I provide service in a common module. But UserProfileComponent cannot subscribe to the event. here are the codes export class UserProfileComponent implements OnInit{ ngOnInit(): void { this.userService.currentMessage.subscribe(message =>...
weka bird
0

votes
2

answer
44

Views

Get timestamp field from snapshot as Timestamp inside Cloud Function Triggers

In typescript, I can create document with field like createdAt, updatedAt as Timestamp by using change.after.updateTime or snap.createTime inside Cloud Functions Triggers. But inside other triggers like onUpdate, the field change.after.data().updatedAt that suppose to store a Timestamp, gives me an...
Gaëtan Rouziès
0

votes
1

answer
13

Views

How do i set the type of this state in my component

How do i set the type of this state in my component state: any = { profile: { details: any: { name: any: '', email: any: '', age: any: '', cellNumber: any: '', } } } class NewNoteForm extends Component { static defaultProps = {profileStore:{}} state = { profile: { details: { name: '', email: '', age...
Hello-World
0

votes
0

answer
16

Views

Refresh side bar menu after saving data in Angular 6

I want to keep updated my sub menu when I adding item into my page. Every time I add any item into my page its added into sub menu. But I need to reload the whole page to see it. Is there any way it will also update the sub menu while I update my page. App-navigation.service.ts getmenu() = AppMenu {...
S.Rusdana
1

votes
1

answer
5.9k

Views

Uncaught Error: [ng:areq] Argument 'fn' is not a function, got undefined

Hi I am trying to build my first Angular app with Typescript but I can not seem to bind a controller correctly. This is my typescript code: module App { var modules: string[] = ["App.Person"]; angular.module('App', modules) .run([]); } module App.Person { angular.module('App.Person', []); } module...
aleczandru
0

votes
3

answer
46

Views

trying to filter an array

I have this code: console.log(this.productlist[this.productlist.length-1] === product); //says: true this.productlist == this.productlist.filter(p => p !== product); console.log(this.productlist); //the product is still in the list I want to filter the product(which is the last item in the list) ou...
nbar
1

votes
1

answer
16

Views

Angular Assigning ngIf class boolean properties when calling function to check for different data types

I am trying to assign different angular class boolean properties to a ngIf but I checked the ngSwitch and ngIf else with templates I don't think those will work. In my sample dataset I have something like this dataSet: [ { total: '$382734.99', clauseName: 'showTotalDollars' }, { total: '3.22%', clau...
c0micrage
0

votes
0

answer
4

Views

Create unit test for function with given parameter

I'm totally new to writing unit tests. I have this function (in abc.test.ts): var fct1 = (param1: string) => { return ("u sent " + param1); }; and I'm trying to write an asynchronous unit test for it using only Mocha. 'till now I have: const asd = require('../abc'); var assert = require('assert');...
user3063909
1

votes
2

answer
35

Views

“moment” has no exported member 'default'

I'm using momement.js for changing the local date format for my application but getting the error: "moment" has no exported member 'default' when importing the library. Below is my code: import {Inject, Injectable, Optional} from '@angular/core'; import {DateAdapter, MAT_DATE_LOCALE, MatDateFormats}...
Amit Golhar
1

votes
0

answer
8

Views

Angular/ng-bootstrap - Change Progressbar with current slide

My intention is to change the progress bar's width with every slide. I'm currently using the progress bar given by bootstrap. So far I'm calling an event in HTML with every slide. This event fetches this information about the slide: Console: {prev: "ngb-slide-0", current: "ngb-slide-1", direction:...
Magiix
1

votes
3

answer
85

Views

How to expose TypeScript modules in NodeJS?

I have a library that I'm building in TypeScript. I'd like to include this library in both TypeScript and JavaScript Node projects. What is the general strategy to do this? Should I compile and have two versions or is there some other strategy I should be using?
Art
2

votes
1

answer
26

Views

Is there such a thing as a “correct” way of defining state with React hooks and Typescript?

I've been working with React for a while, and yesterday I got my feet wet with hooks in a Typescript based project. Before refactoring, the class had a state like this: interface INavItemProps { route: IRoute; } interface INavItemState { toggleStateOpen: boolean } class NavItem extends Component { c...
0

votes
1

answer
37

Views

how to use reference id ( # ) in ngFor and get focus next input?

I have loop ngFor and i need to declare reference id '#' with the index .For eg addRow(){ // after selected data next row to focus. } and i want to focus to next row of select.
rajhim
0

votes
0

answer
5

Views

Implementation problem with an Angular2 component with DynamicDialogRef and without DynamicDialogRef

I'm trying to implement a component with dynamic dialog and there is a need to use a direct usage. With the DynamicDialog example, there is a constructor of the car demo list component. constructor(private carService: CarService, public ref: DynamicDialogRef, public config: DynamicDialogConfig) { }...
Mumin Ka
2

votes
0

answer
15

Views

Typescript: Compose HOCs wrapping components with defaultProps in React

Trying to compose several HOCs (with compose func) seems to lose props annotations altogether, as if making a proper HOC that doesn't lose it wrapped component's defaulted (therefore optional) props wasn't tricky enough. Found some nice workarounds to make HOC preserve optional props of wrapped com...
infctr
1

votes
1

answer
2.3k

Views

Typescript: Assign value to variable from Async function

using Typescript am I trying to assign the return value from an async service call to a local variable as so; private searchResult; public search():void{ this.DashboardService.dashboardSearch(this.searchParams) .then( function (result:ISearchResult) { // promise was fullfilled console.log(resu...
Helmer
2

votes
1

answer
23

Views

How to integrate typescript project with html

I want to call a typescript function from the HTML body. However, I am unable to call my function(D2O_main()) from HTML as I don't fully understand the generated js code. Any help is greatly appreciated. I generated the js using the following command: tsc --module umd main.ts Here's the html file. H...
Sayantan Datta
4

votes
0

answer
23

Views

How to return a list of objects from a function inside a loop

I'm trying to loop over a list of views, and for each view retrieve a list of objects associated with that view, using a service call. Each view is being assigned the result of the last call to the function, instead of the result of the function call with its parameters. Debugging output stateme...
James Muldoon
0

votes
0

answer
4

Views

cannot reference TinyMCE with require.js in TypeScript

I am new in TypeScript. I would appreciate if anyone can guide me to correct path. My Shim looks like require.config({ baseUrl: 'Scripts/', shim: { jquery: { exports: '$' }, bootstrap: { deps: ['jquery'] }, tinyMCE: { exports: 'tinyMCE' } }, paths: { jquery: 'Framework/jquery-3.3.1.min', bootstrap:...
mahfuz01
0

votes
1

answer
24

Views

Convert from type “any” to Object

I'm trying to learn Angular from a online course but the course use an older version of Angular, until now i was able to adapt to Angualar 7 but now i'm stuck in this problem: In the component he defines a Vehicle object of type any, and set its value using an api, like this: "vehicle: any = { featu...
M.Arkk
1

votes
2

answer
179

Views

What is Angular analogue solution for AngularJS interceptors

I have problem with refreshing access_token when it expires. Problem is few services at one time making requests to the server and I need solution to handle all of them,refresh token once and repeat them.
1

votes
2

answer
695

Views

Add property to JQueryStatic interface

I want to add a property someString to the JQueryStatic interface so I can access it with $.someString. In index.ts, I have this code: interface JQueryStatic { someString: string; } $.someString = "string"; $ is of type JQueryStatic, however I get the following error: Property 'someString' does not...
James Monger
0

votes
1

answer
16

Views

Defining a choice of index type on an interface

Lets say i have an interface Animal, and i want it to have some general properties, and then either be a cat or a dog and have corresponding properties. interface Dog { dog: { sound: string; } } interface Cat { cat: { lives: number; } } type CatOrDog = Cat | Dog; interface Animal { weight: number; /...
Pavlo
0

votes
0

answer
3

Views

TypeScript: Enforce generic inferred type parameter in function

Is there a way to restrict the run call below to be strict about the type allowed by the type parameters specified to the RequestType? The return type R seems to work, but RQ isn't strict. class RequestType { constructor(public readonly method: string) { } } interface FooRequest { foo: string; bar:...
Eric Amodio
1

votes
1

answer
4

Views

devextreme-datagrid update: message: “Http failure response for (unknown url): 0 Unknown Error”

I'm having trouble updating the devextreme-datagrid.  Could you help? lineController.js router.put("/:id", (req, res) => { if (!ObjectId.isValid(req.params.id)) return res.status(400).send(`No record with given id : ${req.params.id}`); console.log({ msg: "Line guncelleme işlemi", gelenveri: req.bo...
4

votes
0

answer
27

Views

Typescript changes not compiling after git merge

I am working in a small team environment. When I merge in a change from a separate branch and try to recompile, the compiler doesn't notice any changes to the files affected by the merge. After manually editing the affected files (adding or removing a space) the compiler picks up the changes. This m...
Mike T.
1

votes
1

answer
342

Views

“Cannot read property of undefined” when calling a components view model function from outside the component in Aurelia w/ TypeScript

It was my understanding that with view-model.ref I could access the viewmodel of the component from outside the component and call it's functions. Below code results in Cannot read property 'LoadForAdditionalLocations' of undefined Component to Import export class UserLocationSelector { public LoadF...
Samuel Elrod
1

votes
2

answer
880

Views

Calling a TypeScript function from a Chart.js option callback

I'm using a wrapper for Chart.js which allows for an animation callback to determine when the chart is done drawing. So, my chart options look like this: public chartOptions: any = { animation: { duration: 2000, onComplete: function () { //alert('anim complete'); this.chartTestMethod(); } }, respon...
Roka545
1

votes
1

answer
1.2k

Views

Mongoose typing issue with typescript

I am building an app using mongoose and typescript. Here is a simple model I have made: import * as callbackMongoose from 'mongoose'; var mongoose = callbackMongoose; mongoose.Promise = global.Promise; const Schema = mongoose.Schema; var userSchema = new Schema({ username: String, email: String, ha...
user5505266
1

votes
1

answer
27

Views

Angular ngFor reading subarrays into list-items

I am building a mat-list with mat-list-item. I am having problems with reading the subarrays into my list UI control. It shows up blank. For the part of the collection that does not involve subarrays, it shows up but the data in the subarrays are not incorrectly read with my ngFor angular code. I g...
c0micrage
0

votes
0

answer
4

Views

Is there a way to collect all methods and their paths from NestJS application?

I need to write middleware to process requests, but some of paths should be excluded. I don't want manually hardcode all of them, so I have an idea: Create special decorator, which will tag methods to exclude, something like this: import { ReflectMetadata } from '@nestjs/common'; export const Exclud...
yumaa
2

votes
0

answer
10

Views

Nativescript shared schema in VSCode always redlines classes with error “experimental support for decorators…” error

I've tried everything, reloaded, allowJS, switching between the values of these two: "emitDecoratorMetadata": true, "experimentalDecorators": true, in tsconfig.json and adding it to tsconfing.tns.ts as well. Turning plugins off, uninstalling them outright, nothing seems to work! The error persists.
SebastianG
1

votes
2

answer
2.3k

Views

What to use instead of Object.assign in TypeScript

I am using a mapped type in my typescript source, that I am reusing throughout my project: type StringUnion = string | string[]; type StringUnionMap = { [key: string]: StringUnion }; I have to combine two of these maps into one map that contains the entries of both: let map1: StringUnionMap = { "key...
Sefe
1

votes
1

answer
340

Views

Creating JSON object from Typescript class

I have a class Person and after setting its properties, figuring out best way to convert that class to json object. class Person { firstName: string; lastName: string; } let person = new Person(); person.firstName = "FirstName"; person.lastName = "LastName"; If i do person.getJson() it should give j...
raoul.nair

View additional questions