Hi all!
I am using Cocos Creator 3.8.8.
I encountered different behavior when launching the game in different ways:
- Preview in Prowser.
- Build web-mobile, launching the server and opening the game in the browser.
In the first case, everything works as it should, in the second there was a behavior error.
The error was caused by the generated JavaScript code.
I see that the installed editor contains typescript package version 5.8.2.
The Cocos Creator project has a tsconfig.json file. It references another file, but the final contents are as follows (excluding types and paths):
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"target": "ES2015",
"module": "ES2015",
"strict": false,
"experimentalDecorators": true,
"isolatedModules": true,
"moduleResolution": "node",
"noEmit": true,
"forceConsistentCasingInFileNames": true
}
}
So, I created an empty Node.js project and installed the same version of the TypeScript compiler. Now I’ll compile the following code in both the Node.js project (removing noEmit) and the Cocos Creator project:
let set = new Set<number>();
set.add(1);
set.delete(1);
let array = [...set];
console.log(`Info: set_size = ${set.size}, array_length = ${array.length}`);
The resulting code in the Node.js project:
let set = new Set();
set.add(1);
set.delete(1);
let array = [...set];
console.log(`Info: set_size = ${set.size}, array_length = ${array.length}`);
The resulting code in the Cocos Creator project:
var set = new Set();
set.add(1);
set["delete"](1);
var array = [].concat(set);
console.log("Info: set_size = " + set.size + ", array_length = " + array.length);
Differences:
set.delete(1);
set["delete"](1);
let array = [...set];
var array = [].concat(set);
From Node.js in the console:
Info: set_size = 0, array_length = 0
From Cocos Creator in the console:
Info: set_size = 0, array_length = 1
What is Cocos Creator telling the TypeScript compiler that’s causing the code to contain an error? This needs to be fixed.