I recently discovered X3D and I tried to start writing code for generating a scene into HTML. After installing the package and setting up the typescript configuration, it cannot find the types like X3DBrowser, ProfileInfo or X3DScene. I can only default-import X3D but proper types are not accessible in type expressions.
import X3D from "x_ite" // no swiggles here but does not provide useful types
//import { X3D, X3DBrowser } from "x_ite" // error
let browser: X3D.X3DBrowser = X3D.getBrowser() // getBrowser() is found, X3DBrowser is not a type however
Same for equivalent imports.
My typescript configuration is
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig to read more about this file */
/* Projects */
"incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
/* Language and Environment */
"target": "ES2023", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
/* Modules */
"module": "ES2022", /* Specify what module code is generated. */
"rootDir": "./src/", /* Specify the root folder within your source files. */
"moduleResolution": "bundler", /* Specify how TypeScript looks up a file from a given module specifier. */
/* Emit */
"outDir": "./dist/", /* Specify an output folder for all emitted files. */
/* Interop Constraints */
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
/* Type Checking */
"strict": true, /* Enable all strict type-checking options. */
"strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
"strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
"strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
"noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
}
}
(The additional strict settings are probably redundant.)
I found, properties cannot be used as types in Typescript. var browser: X3D.X3DBrowser will fail but var browser: X3D["X3DBrowser"] works which is short for typeof X3D.X3DBrowser (in the case of X3D being an interface).
I found many errors (red swiggles) in the .d.ts file, including typescript errors (export = … cannot be used together with export default, wrong type number?), references to non-existing types fieldProxy and X3DMaterialExtensionNodeProxy in the autogenerated code, typing errors (overriding type rule checks failed).
I fixed all of the problems and eventually made it work as originally intended by the code (using a namespace instead of an interface). I gonna make a PR draft only for the purpose of showing the changes that work for me. Unfortunately, the autogenerated code is affected too (undefined type names and wrong override types).
Using Typescript 5.6.2, VSCode 1.93.1.
I recently discovered X3D and I tried to start writing code for generating a scene into HTML. After installing the package and setting up the typescript configuration, it cannot find the types like
X3DBrowser
,ProfileInfo
orX3DScene
. I can only default-importX3D
but proper types are not accessible in type expressions.Same for equivalent imports.
My typescript configuration is
(The additional strict settings are probably redundant.)
I found, properties cannot be used as types in Typescript.
var browser: X3D.X3DBrowser
will fail butvar browser: X3D["X3DBrowser"]
works which is short fortypeof X3D.X3DBrowser
(in the case ofX3D
being an interface).I found many errors (red swiggles) in the .d.ts file, including typescript errors (
export = …
cannot be used together with export default, wrong typenumber?
), references to non-existing typesfieldProxy
andX3DMaterialExtensionNodeProxy
in the autogenerated code, typing errors (overriding type rule checks failed).I fixed all of the problems and eventually made it work as originally intended by the code (using a namespace instead of an interface). I gonna make a PR draft only for the purpose of showing the changes that work for me. Unfortunately, the autogenerated code is affected too (undefined type names and wrong override types).