-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Make web/design
a separate TypeScript project
#47694
Conversation
515513d
to
8cf5f0e
Compare
tsconfig.node.json
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It appears that this tsconfig was just ignored before, because we didn't run tsc
with --build
flag (so project references didn't work).
After I added that flag, I got a few errors related to Vite files. I hope my fixes are fine 🤞
"composite": true, | ||
"outDir": "../../../build.assets/.cache/ts/design", | ||
"emitDeclarationOnly": true, | ||
"declarationMap": true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works nice in IDE, where "go to file" goes directly to the source file, not a .d.ts
file. In the CLI however, tsc prints a path to the .d.ts
file:
web/packages/teleterm/src/ui/DocumentAccessRequests/RequestList/RequestList.tsx:122:13 - error TS2322: Type 'boolean' is not assignable to type 'string'.
122 isSortable: true,
~~~~~~~~~~
build.assets/.cache/ts/design/src/DataTable/types.d.ts:76:5
76 isSortable?: string;
~~~~~~~~~~
The expected type comes from property 'isSortable' which is declared here on type 'TableColumn<AccessRequest>'
Unfortunately, I didn't find a way to overcome it.
It seems that making `web/design` a separate project slightly changes the behavior of type inference
8cf5f0e
to
36f8d17
Compare
If you make {
"files": [],
"references": [
{ "path": "./tsconfig.node.json" },
{ "path": "./tsconfig.root.json" },
{ "path": "./web/packages/design/tsconfig.json" }
]
} and {
"extends": "./tsconfig.base.json",
"include": [
"e/web/**/*.ts",
"e/web/**/*.tsx",
"e/web/**/*.js",
"e/web/**/*.jsx",
"web/**/*.ts",
"web/**/*.tsx",
"web/**/*.js",
"web/**/*.jsx",
"../web/src/**/*.ts",
"../web/src/**/*.tsx"
],
"compilerOptions": {
"noEmit": true,
"types": ["node", "@types/wicg-file-system-access"]
},
"exclude": [
"web/packages/design/**",
"node_modules",
"**/node_modules/*",
"**/build/app/**",
"**/build/release/**"
]
} You can set {
"compilerOptions": {
"composite": true,
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true,
"noEmit": true
},
"include": [
"e/web/**/*.mts",
"web/**/*.mts",
"web/packages/build/vite",
"web/packages/teleterm/csp.ts"
]
} {
"extends": "../../../tsconfig.base.json",
"include": ["src", "@types", "../../../web/@types"],
"compilerOptions": {
"composite": true,
"noEmit": true
}
} Type checking still seems to work as expected (I made a change in a vite config and it complained, I added It does, however, surface one type issue for some reason, that your PR doesn't
|
Yeah, it does seem to work... but I'm curious why :)
My concern is that this might be working due to relying on undocumented behavior, and a future TS version can break this. What do you think? |
Ah, this is my bad. I thought I had composite on all of them. Makes sense that you get errors for missing design files - we could not ignore them in |
I guess I'd have to add |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When it comes to project references, AFAIK the best structure is to have tsconfig.json in each package, and then reference them all in the root (just how TypeScript does this). This is currently not possible in our case, because project references don't allow circular imports, and we still have quite a few web/teleport imports in web/shared.
How exactly does this fail? What kind of error do you get?
We have to curb somehow the growth of cyclic imports, even within individual packages as well. Otherwise we'll never get rid of this workaround. We can discuss that under #32940 I suppose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How exactly does this fail? What kind of error do you get?
When each package has its own tsconfig.json
, importing code from one package (e.g., design
) in another (e.g., shared
) requires adding design/tsconfig.json
as a referenced project within shared/tsconfig.json
(otherwise TS won't know where the files for design
are).
If you then try to add shared as design's referenced project you will get a following error:
Project references may not form a circular graph. Cycle detected: /Users/grzegorz/code/teleport/web/design/tsconfig.json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would definitely be perfect to enable once we get rid of those bad imports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!!
Part of #21075
This PR makes
web/design
a separate TS project using project references.This will allow us to enable
strict: true
gradually, starting forweb/design
.When it comes to project references, AFAIK the best structure is to have
tsconfig.json
in each package, and then reference them all in the root (just how TypeScript does this). This is currently not possible in our case, because project references don't allow circular imports, and we still have quite a fewweb/teleport
imports inweb/shared
. Because of that, I madeweb/design
a separate project, everything else is handled by the roottsconfig.json
(ortsconfig.node.json
for Vite stuff).Another thing when using project references is that the referenced project must at least generate declaration files. I was looking for a good place in our repo to store them and found
build.assets/.cache
. I'm not sure if this is the best option, so if you think there's a better place, I'm open to suggestions.