Skip to content

Add API to get symbol type that respects the exactOptionalPropertyTypes option #63829

Description

Please consider adding an API to get type of symbol that takes into account the exactOptionalPropertyTypes option.

Symbols of properties of object types like { a?: string } can be passed to getTypeOfSymbolAtLocation(symbol, symbol.valueDeclaration) and it returns a Type object of a string type. But that will not work with mapped types like Partial<{ a: string }>, because these do not have symbol.valueDeclaration.

I can only use .getTypeOfSymbol() with mapped types, but it does not take into account the exactOptionalPropertyTypes option.

The internal .getNonMissingTypeOfSymbol() does what I want to achieve by passing the result of .getTypeOfSymbol() through the internal .removeMissingType(). (The missingType is also internal.)

It might be too much to have both .getTypeOfSymbol() and .getNonMissingTypeOfSymbol() in the public API. Perhaps .getTypeOfSymbol() could be used to call both via some option or flag (similar to .typeToString())?


Or perhaps there is a solution that I could not figure out?

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions