Does a type assertion / type switch have bad performance / is slow in Go?

It is very easy to write a Benchmark test to check it: http://play.golang.org/p/E9H_4K2J9- package main import ( “testing” ) type myint int64 type Inccer interface { inc() } func (i *myint) inc() { *i = *i + 1 } func BenchmarkIntmethod(b *testing.B) { i := new(myint) incnIntmethod(i, b.N) } func BenchmarkInterface(b *testing.B) { i := … Read more

TypeScript casting arrays

There are 4 possible conversion methods in TypeScript for arrays: let x = []; //any[] let y1 = x as number[]; let z1 = x as Array<number>; let y2 = <number[]>x; let z2 = <Array<number>>x; The as operator’s mostly designed for *.tsx files to avoid the syntax ambiguity.

TypeScript: Convert a bool to string value

This is either a bug in TypeScript or a concious design decision, but you can work around it using: var myBool: bool = true; var myString: string = String(myBool); alert(myString); In JavaScript booleans override the toString method, which is available on any Object (pretty much everything in JavaScript inherits from Object), so… var myString: string … Read more

Build a function object with properties in TypeScript

Update: This answer was the best solution in earlier versions of TypeScript, but there are better options available in newer versions (see other answers). The accepted answer works and might be required in some situations, but have the downside of providing no type safety for building up the object. This technique will at least throw … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)