es-shims / error-cause

An ES-spec-compliant shim/polyfill/replacement for the `.cause` property on all Error types that works as far down as ES3

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Typescript types

conartist6 opened this issue · comments

There are no types, so constructing an error this way in a project with types is still a type error. The needed type is:

interface Error {
  new (reason: string, options?: { cause?: unknown }): Error;

  cause: unknown;
}

Are there any existing examples of how to handle types correctly for both pure (const { Error } = require('error-cause')) and impure (require('error-cause/auto')) usages?

The type for Error is built into TypeScript. It’d be great if you wanted to make a PR to DefinitelyTyped to add types for this package.

Note that there is no import available from the main - you’re looking for require('error-cause/Error'). The type for that should be the same as the type for the global error after auto is used.

Ah ok. I wasn't saying the Error type isn't built into typescript, that's just the syntax TS uses to extend builtin types.

Ah and I was mistaken about the type. It should be:

interface Error {
  cause: unknown;
}

interface ErrorConstructor {
  new (reason: string, options?: { cause?: unknown }): Error;
}

Please add me as a reviewer if you make a DT PR.

(Types are best shipped separately, so as not to conflate the semver of the implementation with that of the types)

Mmm gotta love that megarepo. And I need a newer git in WSL Ubuntu to do a sparse checkout... Maybe I should have built from sources instead? Seems to work though.

lots_of_deps

SyntaxError: Unexpected token } in JSON at position 191
    at JSON.parse (<anonymous>)
    at /home/conartist6/dev/repos/DefinitelyTyped/node_modules/dtslint/bin/util.js:40:21
    at Generator.next (<anonymous>)
    at fulfilled (/home/conartist6/dev/repos/DefinitelyTyped/node_modules/dtslint/bin/util.js:24:58)

It wouldn't even be javascript development if you weren't hampered by the problem you're out to fix while developing the solution.

ERROR: 6:1  expect            TypeScript@4.5 expected type to be:
  'Error'
got:
  "Error"

Thank you so helpful.

Also I'm not allowed to add reviewers and there are apparently two test scripts with different requirements.

Checker 1 (local):
Fails if I don't extend "dtslint/dtslint.json"
Checks four properties on tsconfig.json (agrees with docs)
Checker 2 (CI):
Fails if I don't extend "dtslint/dt.json", (agrees with the docs)
Checks some additional properties on tsconfig.json (undocumented)

Oh and though the docs don't say it if you're adding a package you make a directory but you also need to add it to your sparse checkout or else it will disappear.

I know you don't really care about all this since I'm taking care of it for you, but that's kind of my point. We go tell other devs "oh just go do this thing" and it's almost never remotely that simple or we'd have done it ourselves. Now I know you've made a name for yourself and have lots of important responsibilities, but stuff like this costs me the time (and more importantly the sanity) I'd be using to do the work that would make a name for myself.

Error: At 1:1 : Expected /\/\/ Type definitions for (non-npm package )?/

Another instance of an error message without the crucial runtime data needed to interpret and fix it. Good thing I'm good at guesswork. But that's why I'm doing this I guess.

Hmm ok some more unspecified things that have to go in tsconfig. They couldn't be warned on earlier because apparently the parser just blows up if it doesn't find certain things it's hoping for. Oh and prettier isn't set up to strip trailing commas from json files, though all the parsers treat them as errors.

WHHHHHHHHHHHHHHHHEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE

So my question to you is this? How do you go into development in good faith and not end up incredibly bitter? Is it me? Am I the problem? Also I know what I'm doing! I can't imagine how infuriating this would be for someone who didn't have all the knowledge I have that lets me get to the bottom of these issues pretty rapidly without help.

Error: error-cause: Only index.d.ts may be listed explicitly in tsconfig's "files" entry.
Other d.ts files must either be referenced through index.d.ts, tests, or added to OTHER_FILES.txt.

FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

Error: Unused file ./types/error-cause/error-cause-tests.ts (used files: ["index.d.ts","tsconfig.json","tslint.json"])

So far about four hours of a process about as therapeutic as banging my head on a desk to check in some code that took about half an hour to write.

Isn't this just a self-perpetuating system? Like, I could try to fix all these problems that I've encountered, but I down own that stuff but:

  • It isn't my responsibility
  • There are things I am responsible for
  • I've already used 300% of the time I had to spend on this
Error: Expected file 'tests/auto.test.ts' to be named 'error-cause-tests.ts' or to be inside a './types/error-cause/test/' directory

Yeah but not enough to document it. Maybe alcohol will help me! Let's find out.

Error: Unused file ./types/error-cause/test/Error.test.ts (used files: ["auto.test.ts","pure.test.ts"])

Ah yes a file is not used when it is used by a file that is used. Because of course it isn't.

@ljharb DefinitelyTyped/DefinitelyTyped#56086

IT IS COMPLETE.

If you read all this, I'm sorry.

lol, thanks.

to add people as reviewers in DT, you add their names inside the "Definitions By" section.

Types package is published.