Combining generics with index type

Let’s talk about index signature types and mapped types. They have similar syntax and do similar-ish things, but they’re not the same. Here are the similarities: They are both object types representing a range of properties Syntax: both index signatures and mapped types use bracketed keylike notation within an object type, as in {[Some Key-like … Read more

Disallow call with any

TypeScript really doesn’t want to disallow any from matching a type, since that’s the whole point of any. You might want to rethink any code which relies on rejecting any, so tread lightly. That being said, you can use the new conditional types feature to build a detector for any which can then be used … Read more

Angular 2 View will not update after variable change in subscribe

are you seeing any error on console? This could be due to fact that angular is not running change detection after you have made updates to value. I think you don’t need ngZone.run as it will run code outside the angular zone. this.questionService.onSubmit(form, this.questions).subscribe( (value) => { this.fileLocation = JSON.stringify(value); console.log(this.fileLocation); this.isRequesting = “false”; console.log(this.isRequesting); … Read more

Typescript interface default values

Can I tell the interface to default the properties I don’t supply to null? What would let me do this No. You cannot provide default values for interfaces or type aliases as they are compile time only and default values need runtime support Alternative But values that are not specified default to undefined in JavaScript … Read more

Angular2 – Http POST request parameters

Update for Angualar 4.3+ Now we can use HttpClient instead of Http Guide is here Sample code const myheader = new HttpHeaders().set(‘Content-Type’, ‘application/x-www-form-urlencoded’) let body = new HttpParams(); body = body.set(‘username’, USERNAME); body = body.set(‘password’, PASSWORD); http .post(‘/api’, body, { headers: myheader), }) .subscribe(); Deprecated Or you can do like this: let urlSearchParams = new … Read more

How to avoid imports with very long relative paths in Angular 2?

TypeScript 2.0+ In TypeScript 2.0 you can add a baseUrl property in tsconfig.json: { “compilerOptions”: { “baseUrl”: “.” // etc… }, // etc… } Then you can import everything as if you were in the base directory: import {XyService} from “services/validation/xy.service”; On top of this, you could add a paths property, which allows you to … Read more