TypeScript declarations bug

Post here your questions about the HTML5 / JavaScript for SFS2X

Moderators: Lapo, Bax

moris
Posts: 52
Joined: 17 Aug 2012, 11:11

TypeScript declarations bug

Postby moris » 01 Oct 2019, 12:13

Hello

I tried to use the latest JS API, you added

[NEW] Experimental TypeScript declarations file included, to improve intellisense in IDEs like Visual Studio Code.


but there are such exceptions

Screenshot at Oct 01 13-49-14.png
(229.25 KiB) Not downloaded yet

Screenshot at Oct 01 13-50-28.png
(69.86 KiB) Not downloaded yet

Screenshot at Oct 01 13-50-53.png
(61.16 KiB) Not downloaded yet
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: TypeScript declarations bug

Postby Bax » 02 Oct 2019, 07:25

What IDE are you using? We'd like to be able to reproduce this to see what is going on.
We tested the type definitions in Visual Studio Code and didn't get errors.
Paolo Bax
The SmartFoxServer Team
moris
Posts: 52
Joined: 17 Aug 2012, 11:11

Re: TypeScript declarations bug

Postby moris » 02 Oct 2019, 14:34

In the sfs2x-api.1.7.15.d.t.s file, where API methods are described, in the send (request: BaseRequest) method description the BaseRequest type is not described in the file.

A similar problem, for example, in method descriptions getIntArray(key: string): array; note that the return type “array” also does not exist, can be replace it with [] or Array <T>

WebStorme 2018.3.6, Angular CLI 8.3.4 webpack default settings
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: TypeScript declarations bug

Postby Bax » 03 Oct 2019, 12:44

The d.ts file is generated automatically, so we don't have control over missing descriptions.
We'll try to figure out something...
Paolo Bax
The SmartFoxServer Team
Plaguestrike
Posts: 5
Joined: 15 Jan 2020, 15:33

Re: TypeScript declarations bug

Postby Plaguestrike » 15 Jan 2020, 15:39

hi!

Has any progress been made with this issue? I'm experiencing this exact same issue too.

Here is my development environment:

General info

Editor: Visual Studio Code 1.41.1
OS: macOS Mojave 10.14.6
Node JS: v11.7.0
NPM: 6.5.0

package.json dependencies

"@angular/compiler": "5.2.11"
"ionic-angular": "3.9.3"
"sfs2x-api": "^1.7.15" (although I've tried to import several different ways)

package.json devDependencies
"@ionic/app-scripts": "3.2.1"
"typescript": "^2.9.2"

tsconfig.json

Code: Select all

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [
      "dom",
      "es2015"
    ],
    "module": "es2015",
    "moduleResolution": "node",
    "sourceMap": true,
    "target": "es5"
  },
  "include": [
    "src/**/*.ts"
  ],
  "exclude": [
    "node_modules",
    "src/**/*.spec.ts",
    "src/**/__tests__/*.ts"
  ],
  "compileOnSave": false,
  "atom": {
    "rewriteTsconfig": false
  }
}




Because I'm using other 'npm run' scripts defined, I wasn't able to manually run webpack, is this likely to be part of my problem?


Thanks
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: TypeScript declarations bug

Postby Bax » 16 Jan 2020, 09:08

It is not clear if you are having issues using the API (connect to SFS, etc), or if it is just a matter of intellisense and code completion.
Paolo Bax
The SmartFoxServer Team
Plaguestrike
Posts: 5
Joined: 15 Jan 2020, 15:33

Re: TypeScript declarations bug

Postby Plaguestrike » 21 Jan 2020, 16:05

Bax wrote:It is not clear if you are having issues using the API (connect to SFS, etc), or if it is just a matter of intellisense and code completion.


I don't think the issue I'm having is either of those things, specifically.

I haven't yet got to the point of seeing an API call be made, because there are TypeScript transpile errors that occur once the SFS2X API has been imported, such as Cannot find name 'BaseRequest' - the same errors that moris reported. This happens even without adding any actual commands; simply importing the typescript.

I tried using the HTML5 API in a kind of round-about way, by only referencing it weakly in a JavaScript class and importing that JavaScript class for use in TypeScript, but I couldn't really get that to work.

I really want to use SmartFox in this project, but I also won't be moving away from TypeScript, so I'm really hoping I can get this to work.


Update:

If, as an alternative to using NPM, I download the Client API and add the files into my source code manually:
- sfs2x-api-1.7.15.d.ts
- sfs2x-api-1.7.15.js
- sfs2x-api-1.7.15.js.map

importing via:

Code: Select all

import * as SFS2X from '../../smartfox/sfs2x-api-1.7.15';


I don't get the above errors about BaseRequest and arrays and so on. But, once I instate some code that actually uses the library, I get this error:

Code: Select all

Uncaught TypeError: t.resolve is not a function
    at Object.setNativePromise


The only code I've added is:

Code: Select all

var sfs = new SFS2X.SmartFox();
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: TypeScript declarations bug

Postby Bax » 22 Jan 2020, 10:23

Could you send a very basic project example showing the TypeScript transpile errors?
Possibly the whole project folder, including node modules and all. We tried updating all the tools used to generate our API final package and we'd like to test it. I don't think anything changed in this regards but.. who knows?
If you can create such basic example (with the least amount of dependancies - for example Angular might not be needed for this), please send us the link to download it by email.
Paolo Bax
The SmartFoxServer Team
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: TypeScript declarations bug

Postby Bax » 22 Jan 2020, 11:42

One more thing.
Could you please try the following?
In the project configuration in which you get those TypeScript transpile errors, go to the node_modules/sfs2x-api folder and edit the type definitions file. Try substituting all occurrences of "{array}" with "{Array}". Do the errors related to that keyword go away in this case? If yes, we may have a hint to fix the issue.
Are other errors reported (other than BaseRequest)? If yes, can you please send us a list?
Thank you.

PS: if you provide a test project as mentioned before, we can check the above ourselves.
Paolo Bax
The SmartFoxServer Team
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: TypeScript declarations bug

Postby Bax » 29 Jan 2020, 09:14

We are in the process of releasing a new minor update to the JavaScript API. If would be great if you could provide a feedback on my last message, so that if changes are needed, we can make them available in the coming release. Thank you.
Paolo Bax
The SmartFoxServer Team
Plaguestrike
Posts: 5
Joined: 15 Jan 2020, 15:33

Re: TypeScript declarations bug

Postby Plaguestrike » 07 Feb 2020, 16:07

Bax wrote:Could you send a very basic project example showing the TypeScript transpile errors?


I've tried using Smartfox in a basic Ionic project (one created using their starter wizard, with just one simple screen). That's about as simple as I'll be able to manage. I looked into creating a simpler project so that it doesn't include Ionic, but I don't know how. I don't know what a simple TypeScript project would look like. I'm not familiar with React or Parcel for example; only Ionic, Cordova and Capacitor.

When you envision people using the SFS HTML5 API, is there consideration given for React/Ionic/Capacitor/Cordova projects? Not in terms of any more sophisticated integration with these, but just in terms of pulling in the SFS2X NPM module in these slightly busier frameworks, that obviously have more dependencies. I'm not talking about a large existing project with even more dependencies still, I'm just talking about the cleanest Ionic project possible.

I understand you might not have the time to do this, but I would be interested to see whether your team are able to spawn an Ionic project (with any combination of TypeScript and tools versions), and have SFS2X import correctly.
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: TypeScript declarations bug

Postby Bax » 10 Feb 2020, 08:25

As you may understand, it is almost impossible for us to test all combinations of frameworks, package managers, development tools and what more, in particular speaking of TypeScript.

Our API package is the most simple NPM package you can think of: 1 JavaScript file with no dependancies. It is hard to tell what is wrong with this. We may try a test with Ionic (with which we are not familiar), but I'm not sure when.

Still, it would help if you could try what I suggested before (go to the node_modules/sfs2x-api folder and edit the type definitions file - see my previous reply).
Paolo Bax
The SmartFoxServer Team
Plaguestrike
Posts: 5
Joined: 15 Jan 2020, 15:33

Re: TypeScript declarations bug

Postby Plaguestrike » 10 Feb 2020, 09:56

I did try replacing {array} with {Array} but sadly I still got BaseRequest errors.

Thanks
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: TypeScript declarations bug

Postby Bax » 23 Mar 2020, 11:25

All reported errors should be fixed by the latest 1.7.17 version of the API.
Paolo Bax
The SmartFoxServer Team
Plaguestrike
Posts: 5
Joined: 15 Jan 2020, 15:33

Re: TypeScript declarations bug

Postby Plaguestrike » 23 Mar 2020, 12:03

Bax wrote:All reported errors should be fixed by the latest 1.7.17 version of the API.


Thanks, I'll try it out soon!

Return to “SFS2X HTML5 / JavaScript API”

Who is online

Users browsing this forum: No registered users and 12 guests