Skip to content

Full Codebase Conversion to TypeScript#46

Open
jgarte wants to merge 1 commit intohapijs:masterfrom
jgarte:wip/ts
Open

Full Codebase Conversion to TypeScript#46
jgarte wants to merge 1 commit intohapijs:masterfrom
jgarte:wip/ts

Conversation

@jgarte
Copy link

@jgarte jgarte commented Jul 3, 2025

Hi Hapi devs,

I did some work here in this branch on converting the mimos repository to TypeScript.

Code review is much appreciated.

@damusix mentored me on this conversion.

all best.

@jgarte jgarte changed the title Wip/ts Full Codebase Conversion to TypeScript Jul 3, 2025
@damusix
Copy link

damusix commented Jul 9, 2025

@Marsup thoughts?

Copy link
Contributor

@kanongil kanongil left a comment

Choose a reason for hiding this comment

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

Here are some preliminary comments regarding the typescript integration. I haven't looked at the actual code conversion.

uses: hapijs/.github/.github/workflows/ci-module.yml@master
with:
min-node-version: 14
uses: hapijs/.github/.github/workflows/ci-module.yml@min-node-22-hapi-21
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should still support node 20.

"main": "lib/index.js",
"types": "lib/index.d.ts",
"main": "lib/index.ts",
"type": "module",
Copy link
Contributor

Choose a reason for hiding this comment

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

Switching to modules has implications for how this package can be consumed. It makes it more straightforward in common web contexts, but creates problems when used with commonjs due to async imports.

It also has implications for typescript integration, where local imports require different file extensions.

It might make sense to switch at this time, but it must be a deliberate decision.

Copy link
Author

Choose a reason for hiding this comment

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

Hi, thanks for the reviews.

The move to "type": "module" is intentional.

package.json Outdated
"test-cov-html": "lab -a @hapi/code -r html -o coverage.html -L"
"test": "node --experimental-strip-types --test --experimental-test-coverage --test-coverage-branches=100 --test-coverage-functions=100 --test-coverage-lines=100 --test-coverage-exclude=test/** test/**/*.ts",
"lint": "tsc --noEmit && eslint . --ext .js,.ts",
"build": "tsc -p tsconfig.build.json --outDir dist"
Copy link
Contributor

Choose a reason for hiding this comment

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

A separate tsconfig for builds makes sense.

Copy link
Contributor

Choose a reason for hiding this comment

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

What is the point of building into dist? The files are not even published, or otherwise exposed.

package.json Outdated
"repository": "git://github.com/hapijs/mimos",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"main": "lib/index.ts",
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't expect that exposing a .ts file is going to work for users. Node doesn't allow imported modules to be stripped: https://nodejs.org/docs/latest-v23.x/api/typescript.html#type-stripping-in-dependencies

// constructor()
describe('Mimos', () => {

expect.type<Mimos>(mimos);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm sad to see that type testing has been removed.

@jgarte jgarte force-pushed the wip/ts branch 3 times, most recently from 6747391 to 2119429 Compare January 6, 2026 22:16
@jgarte
Copy link
Author

jgarte commented Jan 6, 2026

Hi, I pushed some changes. Let me know what you think at this stage. Thanks for all the reviews.

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.

3 participants