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

Issues with module's types #247

Open
mmerfort opened this issue Apr 1, 2022 · 4 comments
Open

Issues with module's types #247

mmerfort opened this issue Apr 1, 2022 · 4 comments

Comments

@mmerfort
Copy link

mmerfort commented Apr 1, 2022

Describe the bug
Some of the type definitions seems to be faulty or incomplete.

To Reproduce
Steps to reproduce the behaviour:

  1. Bootstrap a new typescript project with the defaults (npm i typescript --save-dev && npx tsc --init)
  2. Install the module via npm (npm install @dice-roller/rpg-dice-roller)
  3. Create an example file index.ts (see below)
  4. Set skipLibCheck to false in tsconfig.json
  5. Run tsc to build the project

Expected behaviour
No type errors show up.

Code snippet

import { DiceRoll } from "@dice-roller/rpg-dice-roller"

const roller = new DiceRoll("6d6")

console.log(roller.toString())

Environment:

  • Node.js 17.3.0 on Windows 10 & Node.js 16.14.2 on Ubuntu 20.04.4 installed from nodesource
  • Module version 5.1.0, 5.0.0 has the same behaviour
@mmerfort mmerfort added the bug label Apr 1, 2022
@GreenImp
Copy link
Collaborator

GreenImp commented Apr 2, 2022

I don't use Typescript myself (Although I really want to, I haven't found the time to look into it).
I've tried following your instructions, but running

./node_modules/typescript/bin/tsc

Throws the following:

error TS18003: No inputs were found in config file '/var/www/projects/typescript-test/tsconfig.json'. Specified 'include' paths were '["**/*"]' and 'exclude' paths were '[]'.


Found 1 error.

I'm assuming this isn't the issue you're referring to? Are you able to provide the error that you're seeing please?

The type definitions are all automatically generated from the doc blocks in the code. I'm happy for a PR to fix any faulty ones.

@mmerfort
Copy link
Author

mmerfort commented Apr 2, 2022

Sorry, I forgot to attach the actual error.
Here it is:

$ npx tsc
node_modules/@dice-roller/rpg-dice-roller/types/dice/FudgeDice.d.ts:18:104 - error TS2304: Cannot find name 'Modifier'.

18     constructor(nonBlanks?: number | undefined, qty?: number | undefined, modifiers?: {} | Map<string, Modifier> | Modifier[] | null | undefined);
                                                                                                          ~~~~~~~~

node_modules/@dice-roller/rpg-dice-roller/types/dice/FudgeDice.d.ts:18:116 - error TS2304: Cannot find name 'Modifier'.

18     constructor(nonBlanks?: number | undefined, qty?: number | undefined, modifiers?: {} | Map<string, Modifier> | Modifier[] | null | undefined);
                                                                                                                      ~~~~~~~~

node_modules/@dice-roller/rpg-dice-roller/types/dice/PercentileDice.d.ts:17:72 - error TS2304: Cannot find name 'Modifier'.

17     constructor(qty?: number | undefined, modifiers?: {} | Map<string, Modifier> | Modifier[] | null | undefined, sidesAsNumber?: boolean | undefined);
                                                                          ~~~~~~~~

node_modules/@dice-roller/rpg-dice-roller/types/dice/PercentileDice.d.ts:17:84 - error TS2304: Cannot find name 'Modifier'.

17     constructor(qty?: number | undefined, modifiers?: {} | Map<string, Modifier> | Modifier[] | null | undefined, sidesAsNumber?: boolean | undefined);
                                                                                      ~~~~~~~~

node_modules/@dice-roller/rpg-dice-roller/types/exceptions/DieActionValueError.d.ts:12:22 - error TS2304: Cannot find name 'StandardDice'.

12     constructor(die: StandardDice, action?: string | null | undefined);
                        ~~~~~~~~~~~~

node_modules/@dice-roller/rpg-dice-roller/types/exceptions/DieActionValueError.d.ts:14:10 - error TS2304: Cannot find name 'StandardDice'.

14     die: StandardDice;
            ~~~~~~~~~~~~

node_modules/@dice-roller/rpg-dice-roller/types/modifiers/CriticalSuccessModifier.d.ts:19:31 - error TS2304: Cannot find name 'ComparePoint'.

19     constructor(comparePoint: ComparePoint);
                                 ~~~~~~~~~~~~

node_modules/@dice-roller/rpg-dice-roller/types/modifiers/Modifier.d.ts:39:18 - error TS2304: Cannot find name 'RollResults'.

39     run(results: RollResults, _context: StandardDice | RollGroup): RollResults;
                    ~~~~~~~~~~~

node_modules/@dice-roller/rpg-dice-roller/types/modifiers/Modifier.d.ts:39:41 - error TS2304: Cannot find name 'StandardDice'.

39     run(results: RollResults, _context: StandardDice | RollGroup): RollResults;
                                           ~~~~~~~~~~~~

node_modules/@dice-roller/rpg-dice-roller/types/modifiers/Modifier.d.ts:39:56 - error TS2304: Cannot find name 'RollGroup'.

39     run(results: RollResults, _context: StandardDice | RollGroup): RollResults;
                                                          ~~~~~~~~~

node_modules/@dice-roller/rpg-dice-roller/types/modifiers/Modifier.d.ts:39:68 - error TS2304: Cannot find name 'RollResults'.

39     run(results: RollResults, _context: StandardDice | RollGroup): RollResults;
                                                                      ~~~~~~~~~~~

node_modules/@dice-roller/rpg-dice-roller/types/modifiers/SortingModifier.d.ts:51:41 - error TS2304: Cannot find name 'StandardDice'.

51     run(results: RollResults, _context: StandardDice | RollGroup): RollResults;
                                           ~~~~~~~~~~~~

node_modules/@dice-roller/rpg-dice-roller/types/modifiers/SortingModifier.d.ts:51:56 - error TS2304: Cannot find name 'RollGroup'.

51     run(results: RollResults, _context: StandardDice | RollGroup): RollResults;
                                                          ~~~~~~~~~

node_modules/@dice-roller/rpg-dice-roller/types/utilities/NumberGenerator.d.ts:26:20 - error TS2304: Cannot find name 'Engine'.

26     browserCrypto: Engine;
                      ~~~~~~

node_modules/@dice-roller/rpg-dice-roller/types/utilities/NumberGenerator.d.ts:27:17 - error TS2304: Cannot find name 'Engine'.

27     nodeCrypto: Engine;
                   ~~~~~~

node_modules/@dice-roller/rpg-dice-roller/types/utilities/NumberGenerator.d.ts:29:17 - error TS2304: Cannot find name 'Engine'.

29     nativeMath: Engine;
                   ~~~~~~

node_modules/@dice-roller/rpg-dice-roller/types/utilities/NumberGenerator.d.ts:64:26 - error TS2304: Cannot find name 'Engine'.

64     constructor(engine?: Engine | {
                            ~~~~~~


Found 17 errors in 7 files.

Errors  Files
     2  node_modules/@dice-roller/rpg-dice-roller/types/dice/FudgeDice.d.ts:18
     2  node_modules/@dice-roller/rpg-dice-roller/types/dice/PercentileDice.d.ts:17
     2  node_modules/@dice-roller/rpg-dice-roller/types/exceptions/DieActionValueError.d.ts:12
     1  node_modules/@dice-roller/rpg-dice-roller/types/modifiers/CriticalSuccessModifier.d.ts:19
     4  node_modules/@dice-roller/rpg-dice-roller/types/modifiers/Modifier.d.ts:39
     2  node_modules/@dice-roller/rpg-dice-roller/types/modifiers/SortingModifier.d.ts:51
     4  node_modules/@dice-roller/rpg-dice-roller/types/utilities/NumberGenerator.d.ts:26

I also forgot to mention that the test file is just called test.ts which then gets transpiled to test.js.
The generated code is still valid so the errors aren't critical.

Output after executing tsc:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const rpg_dice_roller_1 = require("@dice-roller/rpg-dice-roller");
const roller = new rpg_dice_roller_1.DiceRoll("6d6");
console.log(roller.toString());

@JamesSkemp
Copy link
Contributor

I've submitted a PR with partial fixes for this.

There may be a better way to handle this, but the problem is the seven files above reference types in the JS docs, but when the TypeScript definitions are generated they're not getting resolved/imported.

Two files still have issues:

  1. node_modules/@dice-roller/rpg-dice-roller/types/exceptions/DieActionValueError.d.ts
  2. node_modules/@dice-roller/rpg-dice-roller/types/modifiers/Modifier.d.ts

For DieActionValueError StandardDice is referenced in the docs, but not imported.

For Modifier RollGroup, RollResults, and StandardDice are referenced in the docs, but are unknown.

For both of these ESLint errors on a detected dependency cycle.

@JamesSkemp
Copy link
Contributor

Well drat. I just started a new project that uses this and just ran into these issues again ... :|

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

When branches are created from issues, their pull requests are automatically linked.

3 participants