Typescript: infer type of generic after optional first generic

You want something like partial type parameter inference, which is not currently a feature of TypeScript (see microsoft/TypeScript#26242). Right now you either have to specify all type parameters manually or let the compiler infer all type parameters; there’s no partial inference. As you’ve noticed, generic type parameter defaults do not scratch this itch; a default … Read more

What is the original type of interpolated string?

The new interpolated string syntax is part compiler magic and part runtime classes. Let’s go through all the scenarios and see what is actually happening. var s = $”{DateTime.Now}”; This gets compiled as this: string s = string.Format(“{0}”, DateTime.Now); See Try Roslyn for details. string s = $”{DateTime.Now}”; This gets compiled as this: string s … Read more

Main method with generic parameter; why does it work?

This is because a type parameter has a bound: <T extends String> => String <T extends String & AutoCloseable> => String & AutoCloseable And the bytecode after erasure is the same as for the regular main declaration in both cases: public static main([Ljava/lang/String;)V JLS §4.4. Type Variables: The order of types in a bound is … Read more

Why can this generic method with a bound return any type?

This is actually a legitimate type inference*. We can reduce this to the following example (Ideone): interface Foo { <F extends Foo> F bar(); public static void main(String[] args) { Foo foo = null; String baz = foo.bar(); } } The compiler is allowed to infer a (nonsensical, really) intersection type String & Foo because Foo is … Read more

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