traverse1984 / oxide.ts

Rust's Option<T> and Result<T, E>, implemented for TypeScript.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

'.ts' is not a valid suffix for a module - Consider renaming the repo.

rrichardson opened this issue · comments

When using oxide.ts in the latest (anything after 4.2) typescript, I get this error:

index.d.ts:3:53 - error TS2691: An import path cannot end with a '.ts' extension. Consider importing 'oxide.js' instead.

3 import { Option, Some, None, Result, Ok, Err } from "oxide.ts";
                                                       ~~~~~~~~~~                     

IMO it's a bug in tsc, because I'm not trying to import a local file, but a module instead, which should be obvious from the lack of local path separator.

There are a bunch of people complaining about this, also Deno requires file extensions, instead of banning them. I think this restriction will be lifted, but either way, to avoid current and future errors, would you consider renaming oxide.ts to oxide-ts?

see:
microsoft/TypeScript#38149
microsoft/TypeScript#37582
microsoft/TypeScript#44839

Yeah - that seems pretty annoying. Changing the name makes sense.

Buggered it up a bit - but slight issue is that it's not going to be possible to rename to oxide-ts due to being too similar to the original package name. Thoughts?

This error only gets reported when the import failed to resolve to anything—expected if, e.g., someone had written this before running npm install. If you’re getting it in a project that’s fully set up, it means the package isn’t resolving correctly and renaming it will only trade this error for the standard Cannot find module '{0}' or its corresponding type declarations error. You can run tsc --traceResolution to get a log of where the compiler looked to try to find typings. I wonder if this is a problem: https://github.com/traverse1984/oxide-ts/blob/4a3ff234ba9928fa151a998f7ad5d7f359c31be2/package.json#L6

We usually see this pointing to a file, not a directory relying on index-file resolution. I would have thought that index-file resolution does work here, but I can’t remember for sure off the top of my head. Anyway, --traceResolution will tell you. Point is, this is not a bug in tsc and the package does not need to be renamed to fix it. There are other npm packages whose name ends in .ts that work fine too.

Thanks so much for your reply Andrew, clearly I'd misunderstood the problem. @rrichardson Does this resolve your issue?