xeokit / xeokit-sdk

Open source JavaScript SDK for viewing high-detail, full-precision 3D BIM and AEC models in the Web browser.
https://xeokit.io
Other
727 stars 288 forks source link

Convert to TypeScript #672

Closed xeolabs closed 2 years ago

xeolabs commented 3 years ago

Integrate tsc, to automatically build TypeScript source files from the JavaScript source files.

Started in feature branch: https://github.com/xeokit/xeokit-sdk/tree/typescript

xeolabs commented 3 years ago

One issue we need to solve: how to configure tsc to work with Pako.js and ZipJS dependencies. See console output below.

lindsay@zaphod:~/xeokit-sdk$ tsc
src/plugins/NavCubePlugin/CubeTextureCanvas.js:7:1 - error TS9005: Declaration emit for this file requires using private name 'destroy'. An explicit type annotation may unblock declaration emit.

7 function CubeTextureCanvas(viewer, cfg = {}) {
  ~~~~~~~~

src/plugins/XKTLoaderPlugin/parsers/lib/pako.js:1:30 - error TS9005: Declaration emit for this file requires using private name 'Deflate'. An explicit type annotation may unblock declaration emit.

1 /* pako 1.0.10 nodeca/pako */(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.pako = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
                               ~

src/plugins/XKTLoaderPlugin/parsers/lib/pako.js:1:30 - error TS9005: Declaration emit for this file requires using private name 'Inflate'. An explicit type annotation may unblock declaration emit.

1 /* pako 1.0.10 nodeca/pako */(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.pako = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
                               ~

src/viewer/scene/PerformanceModel/PerformanceModel.js:811:7 - error TS9006: Declaration emit for this file requires using private name 'ScratchMemory' from module '"/home/lindsay/xeokit-sdk/src/viewer/scene/PerformanceModel/lib/ScratchMemory"'. An explicit type annotation may unblock declaration emit.

811 class PerformanceModel extends Component {
          ~~~~~~~~~~~~~~~~

src/viewer/scene/mesh/draw/DrawShaderSource.js:4:1 - error TS9005: Declaration emit for this file requires using private name 'DrawShaderSource'. An explicit type annotation may unblock declaration emit.

4 const DrawShaderSource = function (mesh) {
  ~~~~~

src/viewer/scene/scene/Scene.js:1:1 - error TS9005: Declaration emit for this file requires using private name '(Anonymous function)'. An explicit type annotation may unblock declaration emit.

1 import {core} from '../core.js';
  ~~~~~~

src/viewer/scene/webgl/Renderer.js:1:1 - error TS9005: Declaration emit for this file requires using private name 'Renderer'. An explicit type annotation may unblock declaration emit.

1 import {FrameContext} from './FrameContext.js';
  ~~~~~~

Found 7 errors.

lindsay@zaphod:~/xeokit-sdk$ tsc -v
Version 4.3.5
lindsay@zaphod:~/xeokit-sdk$ tsc -v
Version 4.3.5
lindsay@zaphod:~/xeokit-sdk$ tsc
src/plugins/NavCubePlugin/CubeTextureCanvas.js:7:1 - error TS9005: Declaration emit for this file requires using private name 'destroy'. An explicit type annotation may unblock declaration emit.

7 function CubeTextureCanvas(viewer, cfg = {}) {
  ~~~~~~~~

src/plugins/XKTLoaderPlugin/parsers/lib/pako.js:1:30 - error TS9005: Declaration emit for this file requires using private name 'Deflate'. An explicit type annotation may unblock declaration emit.

1 /* pako 1.0.10 nodeca/pako */(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.pako = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
                               ~

src/plugins/XKTLoaderPlugin/parsers/lib/pako.js:1:30 - error TS9005: Declaration emit for this file requires using private name 'Inflate'. An explicit type annotation may unblock declaration emit.

1 /* pako 1.0.10 nodeca/pako */(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.pako = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
                               ~

src/viewer/scene/PerformanceModel/PerformanceModel.js:811:7 - error TS9006: Declaration emit for this file requires using private name 'ScratchMemory' from module '"/home/lindsay/xeokit-sdk/src/viewer/scene/PerformanceModel/lib/ScratchMemory"'. An explicit type annotation may unblock declaration emit.

811 class PerformanceModel extends Component {
          ~~~~~~~~~~~~~~~~

src/viewer/scene/mesh/draw/DrawShaderSource.js:4:1 - error TS9005: Declaration emit for this file requires using private name 'DrawShaderSource'. An explicit type annotation may unblock declaration emit.

4 const DrawShaderSource = function (mesh) {
  ~~~~~

src/viewer/scene/scene/Scene.js:1:1 - error TS9005: Declaration emit for this file requires using private name '(Anonymous function)'. An explicit type annotation may unblock declaration emit.

1 import {core} from '../core.js';
  ~~~~~~

src/viewer/scene/webgl/Renderer.js:1:1 - error TS9005: Declaration emit for this file requires using private name 'Renderer'. An explicit type annotation may unblock declaration emit.

1 import {FrameContext} from './FrameContext.js';
  ~~~~~~

Found 7 errors.
Amoki commented 3 years ago

The solution could be to only transpile .ts files and ignore .js files of to put these two libraries in the lib folder and ignore this folder.

// tsconfig.js
...
"exclude": ["node_modules", "lib"],
zhy1440 commented 3 years ago

Hi @Amoki, our team need to support typescript as well. I found that it has already been able to build typescript souce files in this branch, is there any other work to do before release?

Amoki commented 3 years ago

Which branch are you talking about? I'm not using Typescript, I don't know what is missing.

zhy1440 commented 2 years ago

I mean this branch:https://github.com/xeokit/xeokit-sdk/tree/typescript

Which branch are you talking about? I'm not using Typescript, I don't know what is missing.

zhy1440 commented 2 years ago

@xeolabs When will you plan to release the typescript version?

zhy1440 commented 2 years ago

@xeolabs This branch https://github.com/xeokit/xeokit-sdk/tree/typescript is so old that it is hard to merge the commits from master branch. I recommened that you could create a new branch for typscript based to master and merge the commits from the previous typescript branch.

xeolabs commented 2 years ago

Hi @zhy1440 unfortunately we're not able to promise features to users of xeokit under the AGPL3 - we'd be forever working on features without compensation, if that were the case. Do you by chance represent one of our enterprise users? Or if not, I'd suggest an enterprise agreement, then we can certainly align our road map to your needs.

Regarding typescript, it's not something our paying users have so far had a pressing need for, so we've needed to make it a "medium-term" priority. I will be remaking that branch, but other priority tasks required by our commercial users need to take priority, unfortunately.