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

Inconsistent typescript rules between custom environment compiler and build task #8889

Open
sbland opened this issue May 15, 2024 · 6 comments
Labels

Comments

@sbland
Copy link

sbland commented May 15, 2024

Describe the bug

I have a custom react environment which mostly inherited from @bitdev/react.react-env.

When I run bit check-types or bit compile it has no errors but when I run bit snap -b I get typescript errors. It appears that the check-types function is not running in strict mode but the build pipeline is.

I.e. the compile pipeline doesn't enforce implicit any so the following code pases

function hello(foo)  {
  console.info(foo)
}

but with the build pipeline I would get the error error TS7006: Parameter 'foo' implicitly has an 'any' type.

The tsconfig.json looks like this:

{
  "extends": "@teambit/react.react-env/config/tsconfig.json",
  "exclude": ["artifacts", "public", "dist", "node_modules", "package.json", "**/*.cjs"],
  "include": ["**/*", "**/*.json"]
}

.bit.env.ts file

...

  compiler(): EnvHandler<Compiler> {
    return TypescriptCompiler.from({
      tsconfig: this.tsconfigPath,
      types: resolveTypes(__dirname, [this.tsTypesPath]),
      typescript,
    });
  }


  build() {
    return Pipeline.from([
      TypescriptTask.from({
        tsconfig: this.tsconfigPath,
        types: resolveTypes(__dirname, [this.tsTypesPath]),
        typescript,
      }),
      EslintTask.from({
        eslint: ESLintLib,
        tsconfig: this.tsconfigPath,
        configPath: this.eslintConfigPath,
        pluginsPath: __dirname,
        extensions: this.eslintExtensions,
      }),
      VitestTask.from({
        config: require.resolve('./config/vitest.config.mjs'),
      }),
    ]);
  }

Expected Behavior

bit check-types should fail as strict: true is in the tsconfig

Specifications

  • Bit version:1.6.145
  • Workspace type: harmony/
  • Node version: v18.19.1
  • npm / yarn version: 10.2.4
  • Platform: ubuntu

for harmony workspace

  • relevant env @bitdev/react.react-env.
@GiladShoham
Copy link
Member

can you try running
bit ws-config write --clean
then the check-types again

@sbland
Copy link
Author

sbland commented May 15, 2024

Thanks @GiladShoham I ran that and it added a few tsconfig and eslint files.
check-types still returned no errors.
When I dug into some of the tsconfigs created i noticed that it was actually my node env compnents that were not working as expected. For background info I have 2 custom environments in my workspace.

  • One for node components (which inherits @bitdev/node.node-env)
  • one for React components (which inherits @bitdev/react.react-env).

I noticed that tsconfig files were created in any directory that only contained the components with the custom node env. These tsconfig files appear to not be importing my custom tsconfig.
I then compared the .bit.env files for each environment and noticed in the React environment I had defined protected tsconfigPath = require.resolve('./config/tsconfig.json'); but I hadn't in the node environment.
Adding this seems to have resolved the issue but it seems odd that without this the tsconfig was different between compile and build even though both referred to this.tsconfigPath

@sbland
Copy link
Author

sbland commented May 16, 2024

I now get the correct type checking in VSCode but check-types is still not picking up on the correct tsconfig.
I've tried the following and none give me any type errors from check-types:

  • bit reset --all then bit install then bit check-types (no errors) bit snap -b I then get typescript errors in the build pipeline
  • bit snap" then bit buildI now get thetypescript error: "message": "Debug Failure." but with no context on what failed.

@sbland
Copy link
Author

sbland commented May 20, 2024

After some more testing with a stripped back workspace I found that everything worked until I added one of my react env components that was referencing a node-env component in the types.

I.e.

import { apiEndpoint } from 'my-node-env-component`;

export const apiCall = (): ReturnType<typeof apiEndpoint> => {
...
}

Defining the type explicitly mostly fixed the problems I was having. I'm not sure why this resulted in random type error in my node-env files.

For now I think I have fixed this for my environment but I'd be happy to help if anyone has a similar issue.

@sbland
Copy link
Author

sbland commented May 23, 2024

This issue cropped up again and I'm now certain it is having a component in an environment with a tsconfig with strict: true referencing a component with a tsconfig with strict: false. In this case check types and the IDE do not pick up on strict typing but the builder does. @GiladShoham what should happen here? Should check-types and the builder be consistent and both fail or should neither fail?

@GiladShoham
Copy link
Member

Any chance you can share your workspace?
@davidfirst fyi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants