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

Extraneous errors in "internal" folders in node_modules #2446

Open
DavidArchibald opened this issue Jul 25, 2024 · 1 comment
Open

Extraneous errors in "internal" folders in node_modules #2446

DavidArchibald opened this issue Jul 25, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@DavidArchibald
Copy link
Contributor

DavidArchibald commented Jul 25, 2024

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 DavidArchibald added the bug Something isn't working label Jul 25, 2024
@jasonlyu123
Copy link
Member

jasonlyu123 commented Jul 26, 2024

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'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants