microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.9k stars 29.17k forks source link

Let's consider to use a concrete type for `toolInvocationToken` #231937

Open jrieken opened 1 week ago

jrieken commented 1 week ago

I have seen @isidorn pass a cancellation token as toolInvocationToken when calling invoke. I guess this is because of "looks like a token must be a token" thinking. We could rename the field or (my favourite) use a concrete type (class with private ctor) for this so that using a cancellation token or anything else yields a compile error

roblourens commented 1 week ago

Have runtime validation and never for now. Could explore a shape using unique symbol later but I don't know that it makes the usage any clearer.

jrieken commented 5 days ago

Could explore a shape using unique symbol later but I don't know that it makes the usage any clearer.

I like unique symbol but I couldn't get TS happy when I would use it in type Foo = typeof unique symbol; @connor4312 do you know what I am doing wrong?

connor4312 commented 5 days ago

Unique symbols are pretty special. In for case I think they need to be contained in an interface, like interface MyOpaqueType { readonly _opaque: unique symbol }. With this MyOpaqueType will be type that a consumer cannot construct and is irreplacable (except with any).