不会 tsconfig | tslint 常遇到的问题

1. require('xx-xx') 不能用时 

https://stackoverflow.com/questions/31173738/typescript-getting-error-ts2304-cannot-find-name-require

"compilerOptions": {
    // other options
    "types": [
      "node"
    ]
  }

 

2.第三方 type 用不到时, 比如 hammerjs

https://github.com/angular/material2/issues/1944

{
  "compilerOptions": {
    // other typescript options
    "types": [
      "hammerjs"
    ]
  }
}

 

3. tslint auto fix 

ctrl + shift + p, TSLint: Fix all auto fix ... 

 

4. tslint error 

the selector of compoent should have prefix 'xx'

去 tslint.json, 放下面这个就不检查了, 要检查就 true 然后后面写你的 logic

"directive-selector": [false, "attribute", "myprefix", "camelCase"],
"component-selector": [false, "element", "myprefix", "kebab-case"],
 
let x :string = null! 
如果你清楚自己在干嘛的话可以无视这个检查的.
"no-non-null-assertion": false,
 
如果你不喜欢 const 的话
use const instead of let
"prefer-const": false 
 
 
5.
yarn global add tslint typescript
yarn add tslint typescript --dev
tslint --fix -c ./tslint.json 'projects/admin/**/*{.ts,.tsx}'
 
{
  "rulesDirectory": [
    "node_modules/codelyzer"
  ],
  "rules": {
    "arrow-return-shorthand": true,
    "callable-types": true,
    "class-name": true,
    "comment-format": [
      true,
      "check-space"
    ],
    "curly": true,
    "deprecation": {
      "severity": "warn"
    },
    "eofline": true,
    "forin": true,
    "import-blacklist": [
      true,
      "rxjs/Rx"
    ],    
    "import-spacing": true,
    "indent": [
      true,
      "spaces"
    ],
    "interface-over-type-literal": true,
    "label-position": true,
    "max-line-length": [
      false,
      140
    ],
    "member-access": false,
    "member-ordering": [
      true,
      {
        "order": [
          "static-field",
          "instance-field",
          "static-method",
          "instance-method"
        ]
      }
    ],
    "no-arg": true,
    "no-bitwise": true,
    "no-console": [
      true,
      "debug",
      "info",
      "time",
      "timeEnd",
      "trace"
    ],
    "no-construct": true,
    "no-debugger": true,
    "no-duplicate-super": true,
    "no-empty": false,
    "no-empty-interface": true,
    "no-eval": true,
    "no-inferrable-types": [
      true,
      "ignore-params"
    ],
    "no-misused-new": true,
    "no-non-null-assertion": false,
    "no-shadowed-variable": true,
    "no-string-literal": false,
    "no-string-throw": true,
    "no-switch-case-fall-through": true,
    "no-trailing-whitespace": true,
    "no-unnecessary-initializer": true,
    "no-unused-expression": true,
    "no-use-before-declare": true,
    "no-var-keyword": true,
    "object-literal-sort-keys": false,
    "one-line": [
      true,
      "check-open-brace",
      "check-catch",
      "check-else",
      "check-whitespace"
    ],
    "prefer-const": true,
    "quotemark": [
      true,
      "single"
    ],
    "radix": true,
    "semicolon": [
      true,
      "always"
    ],
    "triple-equals": [
      false,
      "allow-null-check"
    ],
    "typedef-whitespace": [
      true,
      {
        "call-signature": "nospace",
        "index-signature": "nospace",
        "parameter": "nospace",
        "property-declaration": "nospace",
        "variable-declaration": "nospace"
      }
    ],
    "unified-signatures": true,
    "variable-name": false,
    "whitespace": [
      true,
      "check-branch",
      "check-decl",
      "check-operator",
      "check-separator",
      "check-type"
    ],
    "no-output-on-prefix": true,
    "use-input-property-decorator": true,
    "use-output-property-decorator": true,
    "use-host-property-decorator": true,
    "no-input-rename": true,
    "no-output-rename": true,
    "use-life-cycle-interface": true,
    "use-pipe-transform-interface": true,
    "component-class-suffix": true,
    "directive-class-suffix": true,
    "directive-selector": [false, "attribute", "myprefix", "camelCase"],
    "component-selector": [false, "element", "myprefix", "kebab-case"]
  }
}

 

 
 
 
 
 

 

posted @ 2018-05-08 14:51  兴杰  阅读(1441)  评论(0编辑  收藏  举报