feat(58561): allow leading underscore for types to bypass noUnusedLocals warning
This commit is contained in:
Родитель
b1c52c53cc
Коммит
bed38e9592
|
@ -43174,6 +43174,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
function isTypeParameterUnused(typeParameter: TypeParameterDeclaration): boolean {
|
||||
return !(getMergedSymbol(typeParameter.symbol).isReferenced! & SymbolFlags.TypeParameter) && !isIdentifierThatStartsWithUnderscore(typeParameter.name);
|
||||
}
|
||||
|
@ -43194,6 +43195,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
|||
}
|
||||
|
||||
function isValidUnusedLocalDeclaration(declaration: Declaration): boolean {
|
||||
if (isTypeAliasDeclaration(declaration)) {
|
||||
/**
|
||||
* ignore starts with underscore names _
|
||||
* type _T = number;
|
||||
*/
|
||||
return isIdentifierThatStartsWithUnderscore(declaration.name);
|
||||
}
|
||||
if (isBindingElement(declaration)) {
|
||||
if (isObjectBindingPattern(declaration.parent)) {
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
unusedTypeDeclarations.ts(1,6): error TS6196: 'T1' is declared but never used.
|
||||
|
||||
|
||||
==== unusedTypeDeclarations.ts (1 errors) ====
|
||||
type T1 = number; // error
|
||||
~~
|
||||
!!! error TS6196: 'T1' is declared but never used.
|
||||
type _T2 = number; // ok
|
||||
|
||||
export {};
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
//// [tests/cases/compiler/unusedTypeDeclarations.ts] ////
|
||||
|
||||
//// [unusedTypeDeclarations.ts]
|
||||
type T1 = number; // error
|
||||
type _T2 = number; // ok
|
||||
|
||||
export {};
|
||||
|
||||
|
||||
//// [unusedTypeDeclarations.js]
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@ -0,0 +1,11 @@
|
|||
//// [tests/cases/compiler/unusedTypeDeclarations.ts] ////
|
||||
|
||||
=== unusedTypeDeclarations.ts ===
|
||||
type T1 = number; // error
|
||||
>T1 : Symbol(T1, Decl(unusedTypeDeclarations.ts, 0, 0))
|
||||
|
||||
type _T2 = number; // ok
|
||||
>_T2 : Symbol(_T2, Decl(unusedTypeDeclarations.ts, 0, 17))
|
||||
|
||||
export {};
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
//// [tests/cases/compiler/unusedTypeDeclarations.ts] ////
|
||||
|
||||
=== unusedTypeDeclarations.ts ===
|
||||
type T1 = number; // error
|
||||
>T1 : number
|
||||
> : ^^^^^^
|
||||
|
||||
type _T2 = number; // ok
|
||||
>_T2 : number
|
||||
> : ^^^^^^
|
||||
|
||||
export {};
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
// @noUnusedLocals: true
|
||||
|
||||
type T1 = number; // error
|
||||
type _T2 = number; // ok
|
||||
|
||||
export {};
|
Загрузка…
Ссылка в новой задаче