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

Make web/design a separate TypeScript project #47694

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

gzdunek
Copy link
Contributor

@gzdunek gzdunek commented Oct 18, 2024

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 for web/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 few web/teleport imports in web/shared. Because of that, I made web/design a separate project, everything else is handled by the root tsconfig.json (or tsconfig.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.

@gzdunek gzdunek added no-changelog Indicates that a PR does not require a changelog entry developer-experience Addressing these issues will improve the experience of developers working on Teleport labels Oct 18, 2024
Copy link
Contributor Author

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,
Copy link
Contributor Author

@gzdunek gzdunek Oct 18, 2024

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
@ryanclark
Copy link
Contributor

ryanclark commented Oct 23, 2024

If you make tsconfig.json

{
  "files": [],
  "references": [
    { "path": "./tsconfig.node.json" },
    { "path": "./tsconfig.root.json" },
    { "path": "./web/packages/design/tsconfig.json" }
  ]
}

and tsconfig.root.json (maybe this can go in a different folder)

{
  "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 noEmit in both tsconfig.node.json and design/tsconfig.json

{
  "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 strict: true to design's tsconfig.json and it complained only about strict things in the design directory)

It does, however, surface one type issue for some reason, that your PR doesn't

web/packages/design/src/Image/Image.tsx:59:12 - error TS2339: Property 'propTypes' does not exist on type 'styleFn'.

59   ...space.propTypes,
              ~~~~~~~~~

web/packages/design/src/Image/Image.tsx:60:12 - error TS2339: Property 'propTypes' does not exist on type 'styleFn'.

60   ...color.propTypes,
              ~~~~~~~~~

web/packages/design/src/Image/Image.tsx:61:12 - error TS2339: Property 'propTypes' does not exist on type 'styleFn'.

61   ...width.propTypes,
              ~~~~~~~~~

web/packages/design/src/Image/Image.tsx:62:13 - error TS2339: Property 'propTypes' does not exist on type 'styleFn'.

62   ...height.propTypes,
               ~~~~~~~~~

web/packages/design/src/Image/Image.tsx:63:15 - error TS2339: Property 'propTypes' does not exist on type 'styleFn'.

63   ...maxWidth.propTypes,
                 ~~~~~~~~~

web/packages/design/src/Image/Image.tsx:64:16 - error TS2339: Property 'propTypes' does not exist on type 'styleFn'.

64   ...maxHeight.propTypes,
                  ~~~~~~~~~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
developer-experience Addressing these issues will improve the experience of developers working on Teleport no-changelog Indicates that a PR does not require a changelog entry size/sm ui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants