Skip to content

Begin migration to typescript - #1186

Merged
internettrans merged 7 commits into
7.0from
ts-1
Feb 14, 2024
Merged

Begin migration to typescript#1186
internettrans merged 7 commits into
7.0from
ts-1

Conversation

@internettrans

@internettrans internettrans commented Jan 3, 2024

Copy link
Copy Markdown
Member

This sets up the migration to typescript, by getting the type declarations, tests, and build working with typescript. It will be followed up with more PRs to migrate the source files. This PR is going into a new 7.0 branch since the migration to typescript will be a breaking change.

Comment thread package.json
"import": "./lib/es2015/esm/single-spa.dev.js",
"require": "./lib/es2015/umd/single-spa.dev.cjs"
"require": "./lib/es2015/umd/single-spa.dev.cjs",
"types": "./typings/single-spa.d.ts"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Do we need separate types for import/require? With a .cts extension? I'm looking at https://github.com/single-spa/single-spa-react/pull/197/files#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519R16 for reference and am unsure

Comment thread package.json
"@rollup/plugin-commonjs": "^19.0.0",
"@rollup/plugin-node-resolve": "^13.0.0",
"@rollup/plugin-replace": "^2.3.1",
"@rollup/plugin-terser": "^0.4.4",

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The old terser plugin wasn't working for some reason with babel preset typescript, so I upgraded to it

Comment thread src/single-spa.ts
window.__SINGLE_SPA_DEVTOOLS__.exposedMethods = devtools;
}

declare global {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I initially had this in a separate file globals.ts but ended up colocating it with where __SINGLE_SPA_DEVTOOLS__ is defined. I have my own typescript patterns that are fairly loose but don't involve a strict folder/file structure. I prefer colocating interfaces in the files that use them much of the time. Perhaps over time, we can develop more established typescript patterns for single-spa projects. I'm open to feedback on typescript patterns - generally I don't prefer lots of folders and files when inlining interfaces does fine

Comment thread typings/single-spa.d.ts
@@ -1,238 +0,0 @@
declare module "single-spa" {
interface CustomProps {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'll move many of these types into .ts source files in subsequent PRs.

@internettrans
internettrans merged commit a061710 into 7.0 Feb 14, 2024
@internettrans
internettrans deleted the ts-1 branch February 14, 2024 05:20
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