Skip to content

More stale errors in tsbuildinfo file (with incremental:true) #49527

@samreid

Description

@samreid

Bug Report

@zepumph and I observed incorrect behavior from tsc when incremental was set to true. A similar behavior was also discussed in #42769. It seems like the tsbuildinfo is stale.

🔎 Search Terms

incremental, stale, tsbuildinfo

🕗 Version & Regression Information

  • This is the behavior in 4.6.3 and 4.7.3

💻 Code

// ###################### js/MessageablePerson.ts ##############
const Messageable = () => {
  return class MessageableClass {
    public message = 'hello';
  }
};

const wrapper = () => Messageable();
type MessageablePerson = InstanceType<ReturnType<typeof wrapper>>;
export default MessageablePerson;

// ###################### js/main.ts ##############
import MessageablePerson from './MessageablePerson.js';

function logMessage( person: MessageablePerson ) {
  console.log( person.message );
}

// ###################### ./tsconfig.json ##############
{
  "compilerOptions": {
    "incremental": true,
    "target": "ES2020",
    "module": "ES2020",
    "declaration": false,
    "outDir": "./outDir",
    "composite": false,
    "noEmit": true
  },
  "include": [
    "js/**/*"
  ]
}

🙁 Actual behavior

  1. Set up the 3 files described above, note the relative paths
  2. Run tsc. Observe that type checking passes, as expected
  3. Change public message = 'hello'; to protected message = 'hello'; and run tsc. Observe that type checking fails, as expected. The error message is js/main.ts:5:23 - error TS2445: Property 'message' is protected and only accessible within class 'MessageableClass' and its subclasses.
  4. Change protected message = 'hello'; back to public message = 'hello'; and run tsc. Observe that type checking fails when it should have succeeded. Same error message as in prior step.
  5. Change "incremental": true, to "incremental": false, in the tsconfig file and run tsc. Observe that type checking succeeds as expected.

🙂 Expected behavior

  • In Step 4, we would have expected no type errors, since message is public. However, tsc reports a type error.
  • In Step 5, we would expect no change in behavior whether incremental is set to true or false.
  • Note that we experimented with combining main into the MessageablePerson file and could not exhibit the bug in that way
  • Note also that the bug appears in both ways: (a) reporting an error when there isn't one and (b) reporting that there is no error when there really is an error.

Metadata

Metadata

Assignees

Labels

Fix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions