Code Monkey home page Code Monkey logo

Comments (8)

pre-martin avatar pre-martin commented on August 19, 2024 6

I get an error message, when using "strict": true in the compiler options:

test.ts:

import * as ReconnectingWebsocket from 'reconnecting-websocket';

const websocket: WebSocket = new ReconnectingWebsocket('url', undefined, {constructor: WebSocket});

tsconfig.json:

{
  "compilerOptions": {
    "target": "es2015",
    "module": "es2015",
    "moduleResolution": "node",
    "strict": true,
    "allowSyntheticDefaultImports": true
  }
}

Compile error:

node node_modules/typescript/lib/tsc.js -p tsconfig.json

test.ts(3,30): error TS7009: 'new' expression, whose target lacks a construct signature, implicitly has an 'any' type.

If I remove "strict": true from tsconfig.json, the code compiles fine. But I want this option to be true.

tsc: 2.4.2
reconnecting-websocket: 3.2.2

from reconnecting-websocket.

pladaria avatar pladaria commented on August 19, 2024

Just published v3.2.0 with noImplicitAny set to true

from reconnecting-websocket.

alex-weaver avatar alex-weaver commented on August 19, 2024

This still seems to be an issue in v3.2.0 and v3.2.1, unless there's a mistake in the import declaration? The code I'm using is as follows:

import ReconnectingWebSocket from 'reconnecting-websocket'
const socket = new ReconnectingWebSocket('ws://my.site.com');

This is using the npm package, referenced in package.json using:
"reconnecting-websocket": "3.2.1"
(Also tried with 3.2.0)

This yields two errors:

TS2350	(TS) Only a void function can be called with the 'new' keyword.
TS7009	(TS) 'new' expression, whose target lacks a construct signature, implicitly has an 'any' type.

Is there a mistake in how I'm importing the library?

from reconnecting-websocket.

slikts avatar slikts commented on August 19, 2024

Is there a mistake in how I'm importing the library?

There isn't, it doesn't seem like the author would have tried actually using their code with TypeScript.

from reconnecting-websocket.

pladaria avatar pladaria commented on August 19, 2024

Hi @alex-weaver,

Thanks for reporting. Should be fixed in v3.2.2

Don't hesitate to open a new ticket if you find any issue :)

from reconnecting-websocket.

pladaria avatar pladaria commented on August 19, 2024

Although this lib was coded with a js app in mind, here you have a working ts example:

import * as WS from 'html5-websocket';
import * as RWS from 'reconnecting-websocket';

const rws = new RWS('ws://echo.websocket.org/', undefined, {constructor: WS});

rws.onopen = () =>
    rws.send('hello');

rws.onmessage = (e) => {
    console.log(e.data);
    rws.close(0, 'bye', {keepClosed: true});
};

from reconnecting-websocket.

fahdk avatar fahdk commented on August 19, 2024

Same error.
Typescript 2.7.2, reconnecting-websocket 3.2.2

  "compilerOptions": {
    "outDir": "build/dist",
    "module": "esnext",
    "target": "es5",
    "lib": ["es6", "dom"],
    "sourceMap": true,
    "allowJs": true,
    "jsx": "react",
    "moduleResolution": "node",
    "rootDir": "src",
    "forceConsistentCasingInFileNames": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "suppressImplicitAnyIndexErrors": true,
    "noUnusedLocals": true
  }

from reconnecting-websocket.

kalmi avatar kalmi commented on August 19, 2024

My understanding is that changing noImplicitAny in the library's tsconfig will have no effect whatsoever when importing as only the importer project's tsconfig will be in effect.

from reconnecting-websocket.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.