Skip to content

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

Closed
@Dremora

Description

@Dremora

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions