We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
开发时命中了一个诡异的 bug, 调用 ts2php 编译 ts 文件时会报错:
src/index.ts:3:11 - error TS2554: Expected 0 arguments, but got 1. 3 debug.log('xxx'); ~~~~~
目录结构如下:
├── build.js ├── package.json └── src ├── deps.ts └── index.ts
各个文件内容如下:
const ts2php_1 = require("ts2php"); const fs_extra_1 = require("fs"); let compiler; function ts2php(filePath) { // @note 复现必选条件1: compiler 必须缓存 if (!compiler) { compiler = new ts2php_1.Ts2Php(); } const options = {}; options.source = fs_extra_1.readFileSync(filePath, 'utf8'); const {phpCode} = compiler.compile(filePath, options); return phpCode; } // @note 复现必选条件2: 必选先是 deps.ts , 然后是 index.ts ts2php('./src/deps.ts'); ts2php('./src/index.ts'); // ts2php('./src/deps.ts');
{ "dependencies": { "ts2php": "0.19.13", "typescript": "3.4.5" } }
class Debug { log(msg: any = '', ...args: any[]) { args.unshift(msg); // @note 复现必选条件3: 函数体里必须没有出现过 ...args, 放开下面一行注释就不会有问题, 仅限于 [email protected], [email protected] 版本下,无论开不开下面的注释,都会报错 // console.log(...args); } } export function makeDebug(name = '') { return new Debug(); }
import {makeDebug} from './deps'; const debug = makeDebug('yldebug'); debug.log('xxx');
安装依赖(npm i)后,执行 node build.js 复现问题。
npm i
node build.js
目前发现复现问题有三个前置条件, 具体见上面代码里的注释 @note 复现必选条件。
@note 复现必选条件
临时的 trick 方案就是根据复现条件3得来的, 将 args 赋值给另一个变量 const argsX = [...args];即可。
args
const argsX = [...args];
The text was updated successfully, but these errors were encountered:
No branches or pull requests
开发时命中了一个诡异的 bug, 调用 ts2php 编译 ts 文件时会报错:
目录结构如下:
各个文件内容如下:
安装依赖(
npm i
)后,执行node build.js
复现问题。目前发现复现问题有三个前置条件, 具体见上面代码里的注释
@note 复现必选条件
。临时的 trick 方案就是根据复现条件3得来的, 将
args
赋值给另一个变量const argsX = [...args];
即可。The text was updated successfully, but these errors were encountered: