Comments (8)
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.
Just published v3.2.0 with noImplicitAny
set to true
from reconnecting-websocket.
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.
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.
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.
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.
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.
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)
- Prevented reconnect HOT 7
- Old websockets do not seem to be terminated HOT 5
- Dequeue Events from send
- does not support http headers HOT 4
- How to use "ws.once" with this library?
- Update this._url on a preexisting ReconnectingWebSocket object HOT 1
- Seems to be broken with API Gateway Websockets HOT 2
- allow passing multiple arguments to send method
- on leave session close event not fired HOT 1
- new ReconnectingWebSocket(url).url always empty string
- WebSocket reconnection fails when using it in a React Native simulator
- WebSocket was closed before the connection was established HOT 5
- Add a user callback After the minuptime check
- I cannot close a connection HOT 2
- Use native EventTarget instead of a custom implementation
- Project abandoned? HOT 5
- This expression is not constructable HOT 1
- Bug: `_disconnect` causes uncaught exception and process to crash if using `ws` library HOT 10
- Bug: `_handleError` does not bubble up actual error reason (e.g. `ECONNREFUSED`)
- Bug: `_getNextDelay` returns `0` while a socket may be reconnecting/connecting
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reconnecting-websocket.