Search code examples
typescriptvisual-studiovisual-studio-2022

Visual Studio 2022 text editor losing color syntax after casting interface


Entire code goes white after I cast an interface like

let object : someInterface = <someInterface> someUnknownHapiRequestPayload

print of text editor

Already tried common things like: update VS22, restore defaults, change text editor and theme settings, recreate the project and other basic things like that

Also, if someone knows how can I cast an unknown type data (that is already validated to my interface schema) to assert its type and instance a new object in a way I can acess its properties like:

object.someInterfacePropertie = someFunction(object.someInterfacePropertie)

This also would be appreciated and possibly solve my problem. I'm new to typescript. Thank you

EDIT:

I was able to bypass it by casting my interface in an alternative way:

let object: someInterface = someUnknownHapiRequestPayload as someInterface

This way it won't bug the text editor. But still, the first one being a valid way, I will report this as a problem for Microsoft.


Solution

  • UPDATE:

    Seems like there was already an issue reported, and Microsoft fixed it. It will be released in Visual Studio 2022 version 17.6 preview 4.

    More info on that here: https://developercommunity.visualstudio.com/t/TypeScript-Syntax-Highlight-Broken/10274299