Skip to content
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

Improvements to the "Usage with TypesScript" page #211

Open
achou11 opened this issue Mar 14, 2025 · 0 comments
Open

Improvements to the "Usage with TypesScript" page #211

achou11 opened this issue Mar 14, 2025 · 0 comments

Comments

@achou11
Copy link
Contributor

achou11 commented Mar 14, 2025

Referring to https://xs-dev.js.org/guide/usage-with-typescript/ as of 4dbbe16, there are a couple of things that don't sit well with me personally:

  1. Some of the language feels overly opinionated

Using TypeScript is an industry standard in 2024.

While I agree with this from my personal experience, I find this statement unnecessarily opinionated. I would prefer to see language that doesn't have any risk of implying that not using TS is somehow non-idiomatic. If I were completely unfamiliar with TS but interested in using it, I would feel more welcomed with softer language such as Using TypeScript is a very popular option for writing JavaScript code.

  1. The Let's get started section is overly prescriptive on tooling.

I shouldn't need to learn how to install and use mise, Bun, or tiged in order to learn how to set up TypeScript in an XS project. I understand that these tools are serving as prerequisites for using a template repository that has the configuration of actual interest, but if that's their sole purpose it would make more sense to just point to the template repo and let the user decide how they want to make use of it.

  1. The TSConfig used in the template repository can be improved

I mentioned this in the Matrix chat but there's an easier way to include all of the relevant types provided by the Moddable SDK. It boils down to having the following in the tsconfig.json (omitting various options for brevity):

{
	"compilerOptions": {
		"typeRoots": ["./node_modules/@types", "./node_modules/@moddable/typings"],
		"types": ["xs"]
	},
}

Using the typeRoots field allows you to avoid having to explicitly specify the XS modules of interest in the types field, which doesn't work well with some of the types provided by Moddable due to nesting (in which case using the paths field becomes helpful).

This is mostly relevant for typechecking but should be useful for projects that convert TypeScript code to JavaScript code. From my testing, this has the intended affect of being able to access the types when importing the various XS modules and using the global types defined by xs. Would be helpful for others to confirm that this works as expected and no other changes are needed.

Depending on other tools being used in the project (such as Node for general project tooling), you may need to update "types" in order to include modules whose types may need to be accessed implicitly:

"types": ["node", "xs"]

In general, I think the page should really focus on addressing the following scenarios:

  1. I want to write TypeScript-flavored JavaScript for an XS project. How do I configure TypeScript to support that?

  2. I want to write pure TypeScript code for an XS project. How do I configure and use TypeScript to do that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant