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

Cannot find module 'tiny-typed-emitter' or its corresponding type declarations.ts(2307) #3

Closed
h-archer opened this issue Sep 9, 2020 · 2 comments

Comments

@h-archer
Copy link

h-archer commented Sep 9, 2020

ButtonBehavior.ts:

import { ButtonBehaviorEvent } from './ButtonBehaviorEvent'
import { TypedEmitter } from 'tiny-typed-emitter';

export class ButtonBehavior extends TypedEmitter<ButtonBehaviorEvent> {

  constructor() {
    super();
    this.emit('buttonBehaviorEvent', 'over', true, true, false);
  }

}

ButtonBehaviorEvent.ts:

export interface ButtonBehaviorEvent {
  
  'buttonBehaviorEvent': (
                            $state: string, 
                            $selected: boolean, 
                            $enabled: boolean, 
                            $pressed: boolean,
                          ) => void;
}

package.json:

{
  "name": "drawing",
  "version": "1.0.0",
  "scripts": {
    "dev": "webpack --mode development",
  },
  "devDependencies": {
    "@types/fabric": "^3.6.8",
    "@types/jquery": "^3.5.1",
    "@types/node": "^14.6.4",
    "css-loader": "^4.2.2",
    "mini-css-extract-plugin": "^0.11.0",
    "sass": "^1.26.10",
    "sass-loader": "^10.0.2",
    "ts-loader": "^8.0.3",
    "typescript": "^4.0.2",
    "webpack": "^4.44.1",
    "webpack-cli": "^3.3.12"
  },
  "dependencies": {
    "tiny-typed-emitter": "^2.0.2"
  }
}

I get the errors:

From VScode:
Cannot find module 'tiny-typed-emitter' or its corresponding type declarations.ts(2307)

After compilation:
ButtonBehavior.ts - TS2315: Type 'EventEmitter' is not generic.
ButtonBehavior.ts - TS2339: Property 'emit' does not exist on type 'ButtonBehavior'.

@binier
Copy link
Owner

binier commented Sep 10, 2020

This package simply provides alternative type definitions for NodeJS's built in EventEmitter. So it won't work in browser if that's where you are using it.

@binier binier closed this as completed Sep 10, 2020
@h-archer
Copy link
Author

h-archer commented Sep 11, 2020

I got it working by adding the following to tsconfig.json

/* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
"moduleResolution": "node"

And now it works in the browser

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

2 participants