import * as moment from 'moment';
import { logger } from './utils/logger';
const x: moment.Moment = moment();
logger.info(x.toString());
tslint.json
๊ตฌ์ฑ:
{
"extends": ["tslint:all", "tslint-eslint-rules", "tslint-config-prettier"],
"rules": {
"completed-docs": [false],
"member-ordering": [
true,
{
"order": [
"public-static-field",
"protected-static-field",
"private-static-field",
"public-instance-field",
"private-instance-field",
"public-constructor",
"protected-constructor",
"private-constructor",
"public-static-method",
"protected-static-method",
"private-static-method",
"public-instance-method",
"private-instance-method"
]
}
],
"no-implicit-dependencies": false,
"no-inferrable-types": false,
"no-null-keyword": false,
"prettier": [
true,
{
"bracketSpacing": true,
"jsxBracketSameLine": false,
"parser": "typescript",
"printWidth": 120,
"semi": true,
"singleQuote": true,
"tabWidth": 4,
"trailingComma": "all",
"useTabs": false
}
],
"variable-name": [true, "allow-leading-underscore", "allow-pascal-case", "ban-keywords", "check-format"]
},
"rulesDirectory": ["tslint-plugin-prettier"]
}
๋ณด๊ณ ๋ ์ค๋ฅ:
/Users/mrandolph/Projects/***/***/src/server/test.ts
ERROR: 4:26 no-unsafe-any Unsafe use of expression of type 'any'.
ERROR: 6:13 no-unsafe-any Unsafe use of expression of type 'any'.
moment.js๋ฅผ ์ฌ์ฉํ๋ ๋ฅ๋ ฅ. ํ์ฌ tslint๋ any
์ ํ์ผ๋ก ๊ฐ์งํ๊ณ ์์ผ๋ฉฐ ์ด๋ linting ์ค๋ฅ๋ฅผ ์ผ์ผํต๋๋ค. ํฅ๋ฏธ๋กญ๊ฒ๋ ํน์ ๋ฉ์๋๋ฅผ ๊ฐ์ ธ์ค๋ ค๊ณ ํ๋ฉด ์ฌ์ ํ ๋์ผํ no-unsafe-any ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.
์์:
import { duration, Duration } from 'moment';
import { logger } from './utils/logger';
const x: Duration = duration(1, 'week');
logger.info(x.toString());
์ถ๋ ฅ์ ์์ฑํฉ๋๋ค:
/Users/mrandolph/Projects/***/***/src/server/test.ts
ERROR: 4:21 no-unsafe-any Unsafe use of expression of type 'any'.
ERROR: 6:13 no-unsafe-any Unsafe use of expression of type 'any'.
์ฃผ์ ์ฌํญ - .d.ts ํ์ผ์ด ์๊ฐ์ ํฌํจ๋์ด ์์ต๋๋ค. @types์์ ์ค์นํ ํ์๊ฐ ์์ต๋๋ค.
์ฃผ์ ์ฌํญ - .d.ts ํ์ผ์ด ์๊ฐ์ ํฌํจ๋์ด ์์ต๋๋ค. @types์์ ์ค์นํ ํ์๊ฐ ์์ต๋๋ค.
๊ฐ์ฌํฉ๋๋ค. ๊ทธ๊ฒ ์ ์ฒซ ์ง๋ฌธ์ด์์ ๊ฒ๋๋ค.
tslint:all
๋ no-unused-variable
ํ์ฑํํฉ๋๋ค. ์ด ๊ท์น์ ๋ค๋ฅธ ์ ํ ๊ฒ์ฌ ๊ท์น์ ๋ฐฉํดํ๋ ๊ฒ์ผ๋ก ์๋ ค์ ธ ์์ต๋๋ค. #2736
no-unused-variable
๋ฅผ ๋นํ์ฑํํ๊ณ ์ค๋ฅ๊ฐ ์ฌ๋ผ์ง๋์ง ํ์ธํ ์ ์์ต๋๋ค.
no-unused-variable์ ๋นํ์ฑํํ๊ณ ์ค๋ฅ๊ฐ ์ฌ๋ผ์ง๋์ง ํ์ธํ ์ ์์ต๋๋ค.
๊ทธ๊ฒ ํจ๊ณผ๊ฐ ์์๋ค. ํ์ง๋ง no-unused-variable
๋ ์ฌ์ฉํ๋ ค๋ฉด ์ด๋ป๊ฒ ํด์ผ ํฉ๋๊น? ์ด๊ฒ์ด ๋ด ํ๋ก์ ํธ์ ์๊ฐ์๋ง ์ํฅ์ ๋ฏธ์น๋ ๊ฒ์ฒ๋ผ ๋ณด์ด๋ ์ด์ ๋ - ์ ๊ฐ์ ธ์ค๋ ๋ค๋ฅธ ๋ง์ ํ์ฌ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ์์ต๋๋ค.
๊ทธ๋ฌ๋ ์ฌ์ฉํ์ง ์๋ ๋ณ์๋ ์ฌ์ฉํ๋ ค๋ฉด ์ด๋ป๊ฒ ํด์ผ ํฉ๋๊น?
๋ช ๊ฐ์ง ์ต์ ์ด ์์ต๋๋ค.
--noUnusedLocals
๋ฐ --noUnusedParameters
๋์ ์ฌ์ฉํ์ญ์์ค.no-unused-variable
์์ด ์คํํ๊ณ ๋ ๋ฒ์งธ๋ no-unused-variable
๋ง ์คํํฉ๋๋ค.์ด๊ฒ์ด ๋ด ํ๋ก์ ํธ์ ์๊ฐ์๋ง ์ํฅ์ ๋ฏธ์น๋ ๊ฒ์ฒ๋ผ ๋ณด์ด๋ ์ด์ ๋ - ์ ๊ฐ์ ธ์ค๋ ๋ค๋ฅธ ๋ง์ ํ์ฌ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ์์ต๋๋ค.
๋ฌด์์ด ์๋ชป๋๊ณ ์ ์๋ชป๋์๋์ง๋ ์๋ฌด๋ ๋ชจ๋ฆ ๋๋ค. ๊ท์น์ ์ด๋ป๊ฒ ๋ typescript์ ๋ด๋ถ๋ฅผ ์๋ง์ผ๋ก ๋ง๋ญ๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
๋ช ๊ฐ์ง ์ต์ ์ด ์์ต๋๋ค.
--noUnusedLocals
๋ฐ--noUnusedParameters
๋์ ์ฌ์ฉํ์ญ์์ค.no-unused-variable
์์ด ์คํํ๊ณ ๋ ๋ฒ์งธ๋no-unused-variable
๋ง ์คํํฉ๋๋ค.๋ฌด์์ด ์๋ชป๋๊ณ ์ ์๋ชป๋์๋์ง๋ ์๋ฌด๋ ๋ชจ๋ฆ ๋๋ค. ๊ท์น์ ์ด๋ป๊ฒ ๋ typescript์ ๋ด๋ถ๋ฅผ ์๋ง์ผ๋ก ๋ง๋ญ๋๋ค.