describe('Action', () => {
describe('actionCreator', () => {
type DummyActionType = 'FOO' | 'BAR';
interface Point {
readonly x: number;
readonly y: number;
}
it('creates the correct FSA for primitives', () => {
const creator = actionCreator<DummyActionType, number>('FOO');
creator(7).should.deep.equal({ type: 'FOO', payload: 7 });
});
it('creates the correct FSA for objects', () => {
const creator = actionCreator<DummyActionType, Point>('BAR');
creator({ x: 1, y: 3 }).should.deep.equal({
type: 'BAR',
payload: { x: 1, y: 3 },
});
});
});
});
tslint.json
構成の場合:
{
"defaultSeverity": "error",
"extends": [
// "tslint-microsoft-contrib",
"tslint:recommended",
"tslint-react"
],
"rulesDirectory": [
"./node_modules/tslint-immutable/rules"
],
// additional rules aside from inherited ones
"rules": {
"arrow-parens": [true, "ban-single-arg-parens"],
// possible errors (core TSLint)
"no-switch-case-fall-through": true,
"no-string-throw": true,
// stylistic (core TSLint)
"array-type": [true, "array"],
"interface-name": [true, "never-prefix"],
"no-null-keyword": true,
"no-require-imports": true,
"object-literal-sort-keys": false,
"ordered-imports": [false], // array makes VSCode happy
"quotemark": [true, "single", "jsx-double", "avoid-escape"],
// best practices (core TSLint)
"linebreak-style": [true, "LF"],
"max-file-line-count": [true, 300],
"max-line-length": [true, 100],
"no-magic-numbers": true,
"no-unused-expression": true,
"no-unused-variable": [true, "check-parameters", "react"],
"one-line": [false],
"prefer-const": true,
// functional programming
"no-let": true, // no-var on by default
"no-this": true,
"no-class": true,
"no-new": false, // records?
"readonly-interface": true,
"readonly-indexer": true,
"readonly-array": true,
"no-mixed-interface": true,
// react
"jsx-no-multiline-js": false,
// legal
"file-header": [true, "[+ ]{10,}"]
}
}
タイプエイリアスとインターフェイスを未使用としてマークします。
src/frontend/actions/Action.test.ts
'DummyActionType' is declared but never used. (no-unused-variable)
15 | describe('Action', () => {
16 | describe('actionCreator', () => {
> 17 | type DummyActionType = 'FOO' | 'BAR';
| ^
18 |
19 | interface Point {
20 | readonly x: number;
'Point' is declared but never used. (no-unused-variable)
17 | type DummyActionType = 'FOO' | 'BAR';
18 |
> 19 | interface Point {
| ^
20 | readonly x: number;
21 | readonly y: number;
22 | }
型エイリアスとインターフェイスは一般的な引数として使用され、lintエラーが発生しないようにする必要があります。
Microsoft / TypeScript#14953のように見えます
私のコードはタイプチェックを行うので、Typescriptエラーではないようです。 「回避策」として、tsconfigで"noUnusedLocals"
と"noUnusedParameters"
オンにし、 no-unused-variable
オフにしました。
このファイルでは
import {buildModel} from '../src/compile/common';
import {FacetModel} from '../src/compile/facet';
import {LayerModel} from '../src/compile/layer';
import {Model} from '../src/compile/model';
import {UnitModel} from '../src/compile/unit';
import {initConfig} from '../src/config';
import {ExtendedSpec, FacetSpec, LayerSpec, normalize, TopLevel, UnitSpec} from '../src/spec';
export function parseModel(inputSpec: TopLevel<ExtendedSpec>): Model {
const spec = normalize(inputSpec);
return buildModel(spec, null, '', initConfig(inputSpec.config));
}
export function parseUnitModel(spec: TopLevel<UnitSpec>) {
return new UnitModel(spec, null, '', initConfig(spec.config));
}
export function parseLayerModel(spec: TopLevel<LayerSpec>) {
return new LayerModel(spec, null, '', initConfig(spec.config));
}
export function parseFacetModel(spec: TopLevel<FacetSpec>) {
return new FacetModel(spec, null, '', initConfig(spec.config));
}
これらのエラーが発生します:
ERROR: test/util.ts[7, 9]: 'ExtendedSpec' is declared but never used.
ERROR: test/util.ts[7, 23]: 'FacetSpec' is declared but never used.
ERROR: test/util.ts[7, 34]: 'LayerSpec' is declared but never used.
ERROR: test/util.ts[7, 66]: 'UnitSpec' is declared but never used.
tslintは、ジェネリックスの変数は使用されていないと考えているようです。
インポートを削除できないため、これは非常に面倒です。 今のところ、未使用の変数をチェックするオプションを無効にする必要があります。
これはhttps://github.com/Microsoft/TypeScript/issues/14953ではないと思い@joschaはhttps://github.com/palantir/tslint/issues/2621でクリーンな再現を作成しましたが、インポートは壊れていません(https://gist.github.com/joscha/6633bae73fb4b143cfb685b2754259c9)。 これを優先します。
その場合でも、 React
のインポートがあります(表示されていません)。 代わりにdeclare namespace React { class Component<T, U> {} }
使用すると、エラーはなくなります。
私はまだこの問題を経験しており、 no-unused-variable
はまだtslint5では使用できません。例を提供して喜んでお手伝いします。
私たちはまだこれを経験しています。 これが最小限のレポです(私が見つけることができる最小のもの):
box.ts:
export class Box<T> {
value: T;
}
box_holder.ts:
import { Box } from './box';
export class BoxHolder<T> {
box: Box<T>;
}
結果:
ERROR: src/base/tests/box_holder.ts[3, 24]: 'T' is declared but never used.
バージョン:
興味深いことに、インポートするモジュールの名前が重要なようです。 上記の例でbox_holder.ts
をbox.ts
からインポートし、 box_holder.ts
名前をいくつかの異なる名前に変更すると、次のようになります。
bo.ts
:エラー
bo_.ts
:エラー
bow.ts
:エラー
box_.ts
:エラー
box_holder.ts
:エラー
boxa.ts
:エラーなし
boy.ts
:エラーなし
bx.ts
:エラーなし
これのためにここに来ました。 次の行に沿って、たくさんの新しいlintエラーが発生しています。
ERROR: src/app/app-state.ts[1, 1]: All imports are unused.
ERROR: src/app/app.component.ts[2, 15]: 'Platform' is declared but never used.
ERROR: src/auth/auth.service.ts[2, 10]: 'Http' is declared but never used.
これらはすべて変数として使用されているのではなく、タイプ定義として使用されています。
import { AuthState } from '../auth/models/auth-state'; // <-- "All imports are unused"
export declare interface AppState {
auth: AuthState;
}
これはtypescript@next
で修正されるはずです。 あなたはそれをテストすることができますか?
[email protected]でも同じ問題が発生しています
[email protected]の使用
import * as TypeMoq from 'typemoq';
import { MockedMethod } from '../mocking';
import { IComponent } from '../component'; // <-- All imports are unused
import { IComponentFactory } from '../componentfactory';
export class CreateComponentXMethodMock extends MockedMethod<IComponentFactory, IComponent> {
constructor(mock: TypeMoq.IMock<IComponentFactory>) {
super(mock, x => x.createComponentX(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAnyNumber()));
}
}
OK、問題を再開しました。 https://github.com/Microsoft/TypeScript/issues/14953#issuecomment -302101264
TS2.4で修正済み
tsc
エラーなしでこれが表示されます:
interface SurveyAssetLayersProxyProps {
survey: Survey
}
export default class SurveyAssetLayersControl extends React.Component<SurveyAssetLayersProxyProps, void> {
}
私に与える: ERROR: 19:11 no-unused-variable 'SurveyAssetLayersProxyProps' is declared but never used.
@mikew tslint
がtsc
とは異なるTypeScriptバージョンで実行されている可能性がありますか?
それが可能だとは知りませんでした。 どちらもプロジェクトに関連しており、 ./node_modules/.bin/
です。 これを確認するにはどうすればよいですか?
2017年6月2日には、14:52で、アンディの[email protected]は書きました:
@mikew https://github.com/mikew tslintがtscとは異なるTypeScriptバージョンで実行されている可能性がありますか?
—
あなたが言及されたのであなたはこれを受け取っています。
このメールに直接返信するか、GitHub https://github.com/palantir/tslint/issues/2470#issuecomment-305864709で表示するか、スレッドをミュートしますhttps://github.com/notifications/unsubscribe-auth/AAASeRvhBbEUpy0tQwk_wtObSYT9bsndks5sAEvCgaJp
異なる使い方tsc
でtslint
2.4の正確なバージョンは毎晩、あなたが使用している実際にはない可能性... @mikewを?
あなたたちだけでDEPSをアップグレードするため、今の@adidahiyaが、それは仕事をしませんdevDependencies
ではなく、中にpeerDependencies
。 https://github.com/palantir/tslint/blob/3323ed2b0824a12c8b35c421ebf23c7d17cf788f/package.json#L51を参照して
ああ、私はtslintを削除して再インストールしようとしました。 そして、そのネストされたタイプスクリプトはなくなりました。 糸に問題があります。
v5.6.0でこの問題が発生しています
@tolgaekサンプルコードを提供して--noUnusedLocals
コンパイラオプションを使用してエラーを再現できますか?
こんにちは@ andy-ms簡単なコードでこの問題を再現しようとしましたが、エラーは表示されませんでした。 このエラーは、アプリの複雑さが原因である可能性があります。
また、 noUnusedLocals
実行できません
エラーが表示されるコードは次のとおりです。
import { StepUpProvider } from './step-up.provider';
import { Injectable } from '@angular/core';
import {
Http,
XHRBackend,
RequestOptions,
RequestOptionsArgs,
Response,
Request
} from '@angular/http';
import { Observable } from 'rxjs';
@Injectable()
export class RequestInterceptor extends Http {
constructor(
public backend: XHRBackend,
public defaultOptions: RequestOptions,
private stepUpProvider: StepUpProvider
) {
super(backend, defaultOptions);
}
request(url: string | Request, options?: RequestOptionsArgs): Observable<Response> {
return this.stepUpProvider.intercept(super.request.bind(this, url, options));
}
}
上記のファイルでは、 Response
を使用してrequest
関数の戻り値を入力しているにもかかわらず、 **.ts[8, 3]: 'Response' is declared but never used.
を取得しています。
私はこれをtslint5.10.0とtypescript2.9.2で見ています。 何か案は?
🤖ビープブープ! 👉TSLintは非推奨です👈そしてtypescript-eslintに切り替える必要があります! 🤖
🔒この問題は、これ以上の不必要な議論を防ぐためにロックされています。 ありがとうございました! 👋
最も参考になるコメント
私たちはまだこれを経験しています。 これが最小限のレポです(私が見つけることができる最小のもの):
box.ts:
box_holder.ts:
結果:
バージョン: