2022面试不完全指南

285 阅读1分钟

Q1. VSCode Delete eslint(prettier/prettier)错误

问题根源

由于历史原因,windows下和linux下的文本文件的换行符不一致Windows在换行的时候,同时使用了回车符CR(carriage-return character)换行符LF(linefeed character)MacLinux系统,仅仅使用了换行符LF``老版本的Mac系统使用的是回车符CR。 Windows | Linux/Mac | Old Mac(pre-OSX) | | ------- | :-------: | ---------------: | | CRLF | LF | CR | | ‘\n\r’ | ‘\n’ | ‘\r’|

因此,文本文件在不同系统下创建和使用时就会出现不兼容的问题。

项目仓库中默认是Linux环境下提交的代码,文件默认是以LF结尾的(工程化需要,统一标准)。

windows电脑git clone代码的时候,
如果我的autocrlf(在windows下安装git,该选项默认为true)为true,那么文件每行会被自动转成以CRLF结尾,
如果对文件不做任何修改,pre-commit执行eslint的时候就会提示你删除CR

解决方案

如果是windows系统,文件编码是UTF-8且包含中文,最好全局将autocrlf设置为false

命令行执行

git config --global core.autocrlf false

git全局配置之后,需要重新拉取代码

Q2. import type中的type指什么?

问题根源

JavaScript 进行静态类型检测的检测工具--@flow,@flow的一种写法。当我们定义exoprts.js时,export type MyObject = {  */* ... */*  };那么当我们写imports.js时,就要用import type {MyObject} from './exports';

使用场景

Importing and exporting types**

exports.js

// @flow
export default class Foo {};
export type MyObject = { /* ... */ };
export interface MyInterface { /* ... */ };

imports.js

// @flow
import type Foo, {MyObject, MyInterface} from './exports';

Importing and exporting values

exports.js

// @flow
const myNumber = 42;
export default myNumber;
export class MyClass {
  // ...
}

imports.js

// @flow
import typeof myNumber from './exports';
import typeof {MyClass} from './exports';

官网链接

具体的用法,可以看下@flow官网,下面这个这个用法的链接flow官网