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

Turn remaining files into TypeScript source #758

Merged

Conversation

junlarsen
Copy link
Contributor

Hi! This is a small patch for turning the remainder of the source files into TypeScript.

While I was working on this patch, I noticed we're compiling TypeScript with strict: false which means we lose most of the safety TypeScript gives us. I would be willing to do the necessary changes to enable strict mode in a different patch 😃

As with other parts of the codebase, there are a lot of untyped/loosely typed things which I've just left as-is for now. I've left some TODO comments in the relevant places. I would like some feedback before I commit to any larger changes!

Let me know if there are any questions or concerns. Thanks!

Copy link
Contributor Author

@junlarsen junlarsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are quite a few formatting changes here. These were mostly inserted by my IDE because of the Prettier configuration (as master isn't actually following the prettier config).

It would maybe be an idea to add a CI step to check the formatting.

Comment on lines -12 to +15
export function getBlogPostsByYear({ limit } = {}) {
export function getBlogPostsByYear(limit?: number) {
let count = 0;
return cachedPaths().reduce((years, post) => {
if (limit != null && count >= limit) {
if (limit !== undefined && count >= limit) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it's just as easy to make this limit a regular value, and not an object. It makes it a little nicer to type it as well.

@@ -6,7 +6,7 @@
"scripts": {
"dev": "next dev",
"build": "next build && npm run build:rss && next export",
"build:rss": "node ./scripts/generate-rss-feed.js",
"build:rss": "tsc --outDir dist --noEmit false && sed -i 's/markdown\"/markdown.js\"/g' dist/lib/api.js && node scripts/generate-rss-feed.js",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a small workaround for Webpack not supporting ".js" imports in TypeScript source (TypeScript itself does, but Webpack is the issue here).

Since node with type: module requires full file extensions, I need to rewrite an import in the compiled javascript code.

An alternative would be using something like https://www.npmjs.com/package/tsx or https://www.npmjs.com/package/ts-node to execute TypeScript directly, but I didn't want to add any new dependencies

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do the npm install and npm run dev commands in the readme still work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, nothing has changed there. npm run build:rss also works as expected

@Darksonn
Copy link
Contributor

Darksonn commented Apr 7, 2024

I merged the other PR with automatic formatting. Please resolve the merge conflicts.

@junlarsen junlarsen force-pushed the fix/minimal-typescript-compilation branch from 1f6f899 to 3b0e58e Compare April 7, 2024 11:59
@junlarsen
Copy link
Contributor Author

I merged the other PR with automatic formatting. Please resolve the merge conflicts.

Thanks! I have resolved the conflicts now

Copy link
Contributor

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks sensible to me. I clicked around and it seems like it still works.

@Darksonn Darksonn merged commit b907bdf into tokio-rs:master Apr 8, 2024
7 checks passed
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.

2 participants