More precise inlay type hint for variables after the compiler has infered it

From the screen shot below, the variable baseUrl get type hint 'a. But it has a type string
image
Type hint in the hover below.
image

I’m not entirely sure what your trying to say / ask?

If you are wondering why the variable ends up having a hover with type string, despite of the fact, that you explicitly typed type 'a:

The answer is inference. Either ...[origin] is explictly returning type string, or you are using your variable baseUrl) in a function, which only takes a string. Therefore the compiler infers, your variable has to be of type string, since otherwise your statement wouldn’t be valid.

1 Like

In your let baseUrl: 'a = ..., 'a is a type variable. It represents an unspecified type, which can be instantiated by any type to satisfies the constraint.

Like weops said above, at some point in your program, the compiler infers that the only type that can satisfy the constraint is string, so that’s why you see string.

Yes, i mean, the inlay hint can be the specific type if the compiler has infered it.

Ah sorry I misunderstood you. Are you talking about the inlay type hints with the new vscode extension?

I had thought you had written the : 'a constraint yourself.

Yes. I have also modified the title.