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

A project reference setup using both strict and non-strict modes produces errors in VS Code #50035

Closed
Dremora opened this issue Jul 25, 2022 · 3 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@Dremora
Copy link

Dremora commented Jul 25, 2022

Bug Report

🔎 Search Terms

project references
project references vs code

🕗 Version & Regression Information

When did you start seeing this bug occur?

TypeScript 4.4.2+ (and likely earlier).
Tried 4.8.0-dev.20220725.

This is the behavior in every version I tried, and I reviewed the FAQ for entries about VS Code behaviour.

⏯ Playground Link

GitHub repo (impossible to reproduce in a playground).

💻 Code

🙁 Actual behavior

In a setup with two projects, where foo depends on bar (via project references), foo is using strict mode and bar is not using strict mode, under certain scenarios VS Code will report errors that tsc doesn't.

This seems to happen when in the child project inferred types are generated.

The issue is best understood by looking at the reproduction repo.

In a project (bar) compiled with strict: false, consider a module foo.ts:

export myNumber: number | null = 42;

and index.ts:

import { myNumber } from "./myNumber"

export function getMyNumber() {
  return myNumber;
}

Here, the inferred type of getMyNumber is (): number. If you build the project from the example repo (pnpm tsc -b bar), this will be reflected in the generated .d.ts file, dist/bar/index.d.ts:

export declare function getMyNumber(): number;

You can also build the consuming project, foo, that is using bar, and would only compile if getMyNumber's return type is number:

pnpm tsc -b foo

However, if you open foo/index.ts in VS Code, it will be reporting errors:

image

🙂 Expected behavior

VS Code should behave like the tsc compiler.

@sheetalkamat
Copy link
Member

@Dremora this is kind of known behaviour as currently the editor uses the source files from referenced project insted of d.ts files to give you better experience without having to actually build. The issue arrises when you have different strict settings between projects. Currently you either have to choose between the not having to build referenced project to get seamless experience and these discrepancies in errors.
@weswigham is currently looking into per file strict settings. once we have that we can get better experience in editor for this scenario.

@Dremora
Copy link
Author

Dremora commented Jul 26, 2022

@sheetalkamat thanks for clarification!
Is there a GitHub issue I can track? Found the PR

I've also tried using disableSourceOfProjectReferenceRedirect, and while it resolves the issue, overall it does result in subpar developer experience compared to the default setting, so instead we will be gradually fixing strict mode errors as we encounter them in VS Code.

@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Jul 29, 2022
@typescript-bot
Copy link
Collaborator

This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

4 participants