遇到问题归纳

afcfzf 2021年03月02日 145次浏览
class Person {
    name = 'person';

    sayName = (() => {
	return () => {
            console.log('sayName: ', this.name);
	};
    })();
}

输出什么

ts:

const fn = <T>(): T => ();

const print = (str: string): void;

print(fn()); // 会报类型错误吗?

ts:

定义一个空对象,结果有或没有, 数组感觉不严谨,随便取值都不会出错
interface IObj {
    color: string;
    size: string;
}

const obj: IObj;

ts:
还是回到一个原始问题:类型推导到底能到啥程度,咋实现的

/**
 * 获取层边界int值
 * Array.prototype.map不存在,Array.form 和 spread不可用
 * @param bounds IUnitValue[]
 */
export const getBoundsValue = (bounds: IUnitValue[] | number[]): number[] => {
    const boundsVal = [];
    for (let i = 0; i < bounds.length; i++) {
        boundsVal.push(UnitValue(bounds[i]).as('px'));
    }

    return boundsVal;
};

export const getBoundsPos = (bounds: IUnitValue[] | number[]): {top: number; left: number} => {
    const [left, top] = getBoundsValue(bounds); // 报错吗?

    return {
        top,
        left
    };
};

ts:
ts-node 运行文件,依赖 typings declare ,报错,下面这个就不报错了,为啥。

https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html

browder引用node type 还会报这个!!!
为啥之前bps没报呢

index.js:7 Uncaught TypeError: fs.existsSync is not a function
    at getElectronPath (index.js:7)
    at Object.<anonymous> (index.js:18)
    at Object../node_modules/electron/index.js (index.js:18)
    at __webpack_require__ (bootstrap:789)
    at fn (bootstrap:100)
    at Module.<anonymous> (app.ts:6)
    at Module../src/client/app.ts (app.ts:80)
    at __webpack_require__ (bootstrap:789)
    at fn (bootstrap:100)
    at Module../src/components/RcInstall/model/index.ts (index.tsx:68)