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

How to create a circularly referenced type in TypeScript?

The creator of TypeScript explains how to create recursive types here. The workaround for the circular reference is to use extends Array. In your case this would lead to this solution: type Document = number | string | DocumentArray; interface DocumentArray extends Array<Document> { } Update (TypeScript 3.7) Starting with TypeScript 3.7, recursive type aliases … Read more

Python method-wrapper type?

It appears that the type <method-wrapper ..> is used by CPython for methods implemented in C code. Basically the type doesn’t wrap another method. Instead it wraps a C-implemented function as an bound method. In this way <method-wrapper> is exactly like a <bound-method> except that it is implemented in C. In CPython there are two … Read more