language-tools icon indicating copy to clipboard operation
language-tools copied to clipboard

Extraneous errors in "internal" folders in `node_modules`

Open DavidArchibald opened this issue 1 year ago • 1 comments

Describe the bug

tsc ignores errors in folders named internal in dependencies at a minimum. There may be more situations in which it ignores errors and it seems that svelte-check does not faithfully reproduce these conditions.

Reproduction

You can download this zip svelte-check-reproduction.zip and then:

  1. Unextract the zip.
  2. Inside of it, run npm install.
  3. Move the dependency folder into node_modules (if you do this too early it will be deleted).
  4. Run ./node_modules/typescript/bin/tsc --noEmit and you won't get an error in noIssue.ts
  5. Run ./node_modules/svelte-check/bin/svelte-check and get an error because of reproduction.svelte.

Alternatively if you want to create this situation from scratch:

  1. Create an empty folder.
  2. Initialize a project with npm init or whatever your preferred package manager is.
  3. Run npm install svelte-check.
  4. Create a tsconfig.json with these contents:
{
    "compilerOptions": {
        "strictNullChecks": true,
        "noUncheckedIndexedAccess": true
    }
}
  1. To simulate having an erroring dependency create a node_modules/dependency/internal/index.js file with the contents:
const array = [1, 2, 3];

const item: number = array[4]; // Only an error when noUncheckedIndexedAccess is set to true.
  1. Create a node_modules/dependency/index.js file with the contents import "./internal/index.js";
  2. Create a reproduction.svelte file with the contents:
<script lang="ts">
    import "dependency";
</script>
  1. Run ./node_modules/svelte-check/bin/svelte-check

You should get this error:


====================================
Loading svelte-check in workspace: svelte-check-reproduction
Getting Svelte diagnostics...

svelte-check-reproduction/node_modules/dependency/index.ts:3:7
Error: Type 'number | undefined' is not assignable to type 'number'.
  Type 'undefined' is not assignable to type 'number'. 

const item: number = array[4]; // Only an error when noUncheckedIndexedAccess and strictNullChecks is set to true.


====================================
svelte-check found 1 error and 0 warnings in 1 file

Expected behaviour

I expected no error.

For example in my zip I have a noIssue.ts file with the contents:

import "dependency";

You will not see the issue when you run ./node_modules/typescript/bin/tsc --noEmit nor ./node_modules/svelte-check/bin/svelte-check.

You won't even get an error if you run svelte-check or tsc on the results of svelte2tsx on the contents of reproduction.svelte like so:

import { svelte2tsx } from "svelte2tsx"

const result = svelte2tsx(`<script lang="ts">
    import "dependency";
</script>`);

console.log(result.code);

(you will need to set the package.json type to "type": "module").

This results in:

///<reference types="svelte" />
;
import "dependency";
function render() {

    
;
async () => {};
return { props: /** @type {Record<string, never>} */ ({}), slots: {}, events: {} }}

export default class extends __sveltets_2_createSvelte2TsxComponent(__sveltets_2_partial(__sveltets_2_with_any_event(render()))) {
}

Which does not error (after you resolve the missing dependencies).

System Info

  • OS: Windows/WSL2
  • IDE: VSCode

Which package is the issue about?

svelte-check

Additional Information, eg. Screenshots

No response

DavidArchibald avatar Jul 25 '24 06:07 DavidArchibald

I can't reproduce this I get the error in both tsc and svelte-check. I think you might make some mistake while preparing the reproduction. The dependency/index.ts in your zip is actually import 'internal/index.ts' instead of import './internal/index.ts'.

jasonlyu123 avatar Jul 26 '24 14:07 jasonlyu123