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

Add typescript #5667

Merged
merged 5 commits into from
Sep 1, 2022
Merged

Add typescript #5667

merged 5 commits into from
Sep 1, 2022

Conversation

netpro2k
Copy link
Contributor

@netpro2k netpro2k commented Aug 22, 2022

This adds handling for typescript files to our Webpack config and converts App.js to get things started. It also includes some very basic stubs for AFRAME typing and our threejs modifications. We will continue to build out these stubs as we need them. Our custom BitECS JSX syntax is also supported and components are type checked (though most of the work for this is happening in another branch)

Actual conversion of ts -> js is handled by babel. Importantly this does not perform any typechecking. We do this since we still want our ts code to honor our browserslist targets and polyfills, and so that we can use HMR in the future. It also has the advantage of being faster. Typechecking is performed in parallel at dev time with ForkTsCheckerWebpackPlugin and at build time with npm run check, which actually calls tsc (the typescript compiler). It is configured not to actually emit any files, only check for issues.

Since I was already testing things while adding typescript support to babel I went ahead and finally updated our usage of @babel/polyfill and audited the polyfills we were emitting. I blocked polyfills for Array.prototype.push and Array.prototype.unshift since they have existed basically forever and the polyfill (which we were applying in most cases) is only to handle a strange edgecasee that technically does not match the spec for arrays that for some reason have a readonly length. I also removed some unused transforms.

Using typescript is opt in at a per file level, but the more of the codebase we convert the more we will see benefits (even in our non-js code). If you configure your editor to use the typescript-language-server you should start getting better type hints even in js files.

We should focus first on modules that will have the highest impact, namely anything providing functionality that many other modules depend on. I don't think we really have to strive for 100% code conversion, but it would be very nice if we could get nearly all the "engine" stuff converted. The React parts of the code are fairly low priority as PropTypes does an ok enough job providing some level of type checking.

For cases where you are not ready to convert an entire module but still want to add typing, JSDoc comments can bee used.

@netpro2k netpro2k marked this pull request as ready for review August 22, 2022 22:22
@netpro2k netpro2k merged commit 6fee452 into master Sep 1, 2022
@netpro2k netpro2k deleted the add-typescript branch September 1, 2022 19:43
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

Successfully merging this pull request may close these issues.

1 participant