ts-morph
ts-morph copied to clipboard
Get properties from ObjectType using an EcmaScript symbol instead of a string
Is your feature request related to a problem? Please describe.
Hi.
I have a symbol called HEADERS
, defined as follows:
export const HEADERS = Symbol.for('__headers')
I'm using this symbol to augment the type of a method:
ok<T, Instance extends this>(
body: T,
etag?: boolean
): {
__response: T
__status: GetStatus<Instance, 200>
[HEADERS]: ReturnType<Instance['append']>
}
Now, when I read the AST of this method, I have access to the ObjectType, which is
{
__response: T
__status: GetStatus<Instance, 200>
[HEADERS]: ReturnType<Instance['append']>
}
I want to get the [HEADERS] property using my symbol
type.getProperty(HEADERS)
But that's not possible, cuz the getProperty
method accepts only a string as parameter or a function. For the latter, I did this and it worked
getProperty((property) =>
property.getName().startsWith('__@HEADERS')
)
... but I wonder if it's possible to use only the symbol.
Describe the solution you'd like
The getProperty
method should accept a symbol as parameter.
Describe alternatives you've considered
getProperty((property) =>
property.getName().startsWith('__@HEADERS')
)
Is it possible to achieve this, please?