New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: Accessing CLI-initialized Service #1147
Comments
I think we already expose the https://github.com/TypeStrong/ts-node/blob/master/src/index.ts#L29-L43 Will that work for you? |
Ahhh, yes you do! Apologies for filing this already-solved issue 👍 THANK YOU! |
All good, I am always happy to have an easy answer for you! |
|
Technically we don't always use the language service. We use a different API in |
Makes sense. I'm wondering if there'd be a well-fitting approach to enable some greater introspection via the type-checker (assuming it's enabled). My hope is that I can use a call site to find a particular location in the compiled code, and then use that location to get the source location, to then get type info from the existing type-checker instance. This could open doors to some great experiences. To reiterate, I'd like to do the following within the ts-node process:
Is there any approach with which you'd feel comfortable exposing this functionality? |
For what it's worth, we already install source map support, so call sites should already be mapped to proper I think exposing a I'm not sure if this would work correctly for composite projects, since I think they have multiple programs. |
Unfortunately, it does not seem that the source-mapping extends to call sites :/ const _prepareStackTrace = Error.prepareStackTrace;
Error.prepareStackTrace = (_, stack) => stack;
const frames = new Error().stack?.slice(1) as any as NodeJS.CallSite[];
Error.prepareStackTrace = _prepareStackTrace;
console.log({
column: frames[0].getColumnNumber(), // <-- returns incorrect column number
line: frames[0].getLineNumber(), // <-- returns incorrect line number
}); How would you recommend I get the source location from the compiled source location? And would this require changes to As for accessing the program instance, How should we proceed? |
To add Callsite mapping |
The
You're looking at the third implementation, but any changes to our |
Hmm... not all of those implementations offer a program instance. I suppose it could be an optional field on the For the sake of this tool's longevity, this feature might be out-of-scope :/ I enjoy |
Desired Behavior
I'm building a library, which is intended to be used within a ts-node process. I'd like to be able to access the register so that I can utilize its
getTypeInfo
method.Is this request related to a problem?
As of right now, it is not possible to access the register when you initialize the process via the CLI.
Alternatives you've considered
Monkey-patching, re-initialization, creating an entirely new compiler instance & getting a fresh type-checker.
The text was updated successfully, but these errors were encountered: