language-tools
language-tools copied to clipboard
Extraneous errors in "internal" folders in `node_modules`
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:
- Unextract the zip.
- Inside of it, run
npm install. - Move the
dependencyfolder intonode_modules(if you do this too early it will be deleted). - Run
./node_modules/typescript/bin/tsc --noEmitand you won't get an error innoIssue.ts - Run
./node_modules/svelte-check/bin/svelte-checkand get an error because ofreproduction.svelte.
Alternatively if you want to create this situation from scratch:
- Create an empty folder.
- Initialize a project with
npm initor whatever your preferred package manager is. - Run
npm install svelte-check. - Create a
tsconfig.jsonwith these contents:
{
"compilerOptions": {
"strictNullChecks": true,
"noUncheckedIndexedAccess": true
}
}
- To simulate having an erroring dependency create a
node_modules/dependency/internal/index.jsfile with the contents:
const array = [1, 2, 3];
const item: number = array[4]; // Only an error when noUncheckedIndexedAccess is set to true.
- Create a
node_modules/dependency/index.jsfile with the contentsimport "./internal/index.js"; - Create a
reproduction.sveltefile with the contents:
<script lang="ts">
import "dependency";
</script>
- 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
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'.