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

Parcels not causing any errors with invalid imports or invalid type aliases #9983

Closed
lixoman100 opened this issue Oct 15, 2024 · 1 comment
Closed

Comments

@lixoman100
Copy link

🐛 bug report

Parcel does not generate an error if I try to import a file that does not exist. In addition, importing a Typescript file with type aliases does not seem to make the new types available, causing no errors to pop up when the types are misused.

I have included, below, all the files needed to reproduce my issue.

🎛 Configuration (.babelrc, package.json, cli command)

package.json

{
  "name": "error",
  "version": "1.0.0",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "description": "",
  "devDependencies": {
    "parcel": "^2.12.0",
    "typescript": "^5.6.3"
  }
}

🤔 Expected Behavior

If I run ts-node index.ts, I get these errors:

index.ts:2:21 - error TS2307: Cannot find module './bad' or its corresponding type declarations.
index.ts:5:19 - error TS2322: Type 'number' is not assignable to type 'string'.
index.ts:5:36 - error TS2322: Type 'string' is not assignable to type 'number'.
index.ts:6:5 - error TS2739: Type '{}' is missing the following properties from type 'Good': stringVal, numberVal

This is the expected behavior.

😯 Current Behavior

If I run the same code with parcel index.html, no errors pop up, and I can load the page served by Parcel just fine. The objects will all be constructed properly, despite their definitions being incompatible with the definition on good.ts, ./bad not existing and the definition of Bad not being present.

💁 Possible Solution

I assume this issue is related to tree shaking, causing the imports to never happen. I couldn't find a way to disable tree shaking.

🔦 Context

I am just trying to get started with Parcel, so I assume it's something that I'm doing wrong. Any solutions or workarounds are appreciated.

💻 Code Sample

index.html

<!DOCTYPE html>
<html><head><meta charset="UTF-8">
<script type="module" src="index.ts"></script>
</head><body></body></html>

index.ts

import { Good } from "./good";
import { Bad } from "./bad";

let test1:Good = {stringVal: "test", numberVal: 1234};
let test2:Good = {stringVal: 1234, numberVal: "test"};
let test3:Good = {};

let test4:Bad = {stringVal: "test", numberVal: 1234};
let test5:Bad = {stringVal: 1234, numberVal: "test"};
let test6:Bad = {};

console.log("Hello world!");

good.ts

export type Good = {
    stringVal: string;
    numberVal: number;
}

🌍 Your Environment

Node 20.18.0, Parcel 2.12.0

Software Version(s)
Parcel 2.12.0
Node 20.18.0
npm/Yarn npm 10.8.2
Operating System Windows 11
@lixoman100
Copy link
Author

I finally figured out that you need to add this to .parcelrc:

"validators": {
        "*.{ts,tsx}": ["@parcel/validator-typescript"],
    }

I feel like this shouldn't be necessary, but I fixed my issue, so I'll close this ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant