What does the ampersand (&) mean in a TypeScript type definition?

& in a type position means intersection type. More from typescript docs on Intersection Types: https://www.typescriptlang.org/docs/handbook/2/objects.html#intersection-types Citation from the docs linked above: Intersection types are closely related to union types, but they are used very differently. An intersection type combines multiple types into one. This allows you to add together existing types to get a … Read more

Which is the first integer that an IEEE 754 float is incapable of representing exactly?

2mantissa bits + 1 + 1 The +1 in the exponent (mantissa bits + 1) is because, if the mantissa contains abcdef… the number it represents is actually 1.abcdef… × 2^e, providing an extra implicit bit of precision. Therefore, the first integer that cannot be accurately represented and will be rounded is: For 32-bit floats, … Read more

Defining TypeScript callback type

I just found something in the TypeScript language specification, it’s fairly easy. I was pretty close. the syntax is the following: public myCallback: (name: type) => returntype; In my example, it would be class CallbackTest { public myCallback: () => void; public doWork(): void { //doing some work… this.myCallback(); //calling callback } } As a … Read more

How do I print in Rust the type of a variable?

You can use the std::any::type_name function. This doesn’t need a nightly compiler or an external crate, and the results are quite correct: fn print_type_of<T>(_: &T) { println!(“{}”, std::any::type_name::<T>()) } fn main() { let s = “Hello”; let i = 42; print_type_of(&s); // &str print_type_of(&i); // i32 print_type_of(&main); // playground::main print_type_of(&print_type_of::<i32>); // playground::print_type_of<i32> print_type_of(&{ || “Hi!” … Read more

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