question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

API: Expose a way to figure out the `scriptKind`

See original GitHub issue

Suggestion

🔍 Search Terms

api scriptkind

✅ Viability Checklist

My suggestion meets these guidelines:

  • This wouldn’t be a breaking change in existing TypeScript/JavaScript code
  • This wouldn’t change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn’t a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript’s Design Goals.

⭐ Suggestion

It seems like at the moment the scriptKind property of SourceFile is marked as @internal, it would be nice if this was exposed in the public api.

https://github.com/microsoft/TypeScript/blob/a21024dbe7e79dc018e4193f27ecb66e0465b638/src/compiler/types.ts#L3802-L3804

📃 Motivating Example

I’d like to know if a SourceFile is of ScriptKind.JS, so that I can make specific modifications to .js files only. I could simply check if the SourceFile.fileName ends with .js. But I’d rather make use of the same logic that is used by TypeScript for checking if a file is a JavaScript file. That way I can be sure my application and TypeScript are on the same page of what is and isn’t a JavaScript file.

💻 Use Cases

I have written a basic transformer that makes several modifications to files in a project. And now I’d like to add // @ts-nocheck to all JavaScript files.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
RyanCavanaughcommented, Jul 14, 2022

I don’t see an issue with exposing this, so if you or someone else end up needing this please give another ping and we can evaluate in more detail.

0reactions
sheetalkamatcommented, Aug 2, 2022

Not that i can think of…

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeScript compiler APIs revisited - Scott Logic Blog
I've been following this Github issue for some time, and was pleased to hear that TypeScript 2.2 exposes some AST node factories and...
Read more >
Does TypeScript provide an explicit Public API for NodeJS ...
TypeScriptCompiler, and then you will find that this DOES expose a way of compiling. var compiler = new TypeScript.TypeScriptCompiler(outfile, errorfile ...
Read more >
The practicality of designing and describing your APIs
The web, as we all know, is driven by APIs. Since the rise of mobile applications and the JavaScript driven single-page applications, ...
Read more >
Web of Things (WoT) Scripting API - W3C
This specification describes how to expose and consume Things by a script. ... Discover Things running in the local WoT Runtime.
Read more >
Python and REST APIs: Interacting With Web Services
In this tutorial, you'll learn how to use Python to communicate with REST APIs. ... REST APIs listen for HTTP methods like GET...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found