Skip to content

Commit fd41521

Browse files
author
Andy
authored
Enable 'callable-types' tslint rule (#19654)
1 parent 2ea723f commit fd41521

File tree

10 files changed

+33
-47
lines changed

10 files changed

+33
-47
lines changed

src/compiler/resolutionCache.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,8 @@ namespace ts {
6969

7070
export const maxNumberOfFilesToIterateForInvalidation = 256;
7171

72-
interface GetResolutionWithResolvedFileName<T extends ResolutionWithFailedLookupLocations = ResolutionWithFailedLookupLocations, R extends ResolutionWithResolvedFileName = ResolutionWithResolvedFileName> {
73-
(resolution: T): R;
74-
}
72+
type GetResolutionWithResolvedFileName<T extends ResolutionWithFailedLookupLocations = ResolutionWithFailedLookupLocations, R extends ResolutionWithResolvedFileName = ResolutionWithResolvedFileName> =
73+
(resolution: T) => R;
7574

7675
export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootDirForResolution: string): ResolutionCache {
7776
let filesWithChangedSetOfUnresolvedImports: Path[] | undefined;

src/compiler/scanner.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
/// <reference path="diagnosticInformationMap.generated.ts"/>
33

44
namespace ts {
5-
export interface ErrorCallback {
6-
(message: DiagnosticMessage, length: number): void;
7-
}
5+
export type ErrorCallback = (message: DiagnosticMessage, length: number) => void;
86

97
/* @internal */
108
export function tokenIsIdentifierOrKeyword(token: SyntaxKind): boolean {

src/compiler/types.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2471,9 +2471,13 @@ namespace ts {
24712471
readFile(path: string): string | undefined;
24722472
}
24732473

2474-
export interface WriteFileCallback {
2475-
(fileName: string, data: string, writeByteOrderMark: boolean, onError: ((message: string) => void) | undefined, sourceFiles: ReadonlyArray<SourceFile>): void;
2476-
}
2474+
export type WriteFileCallback = (
2475+
fileName: string,
2476+
data: string,
2477+
writeByteOrderMark: boolean,
2478+
onError: ((message: string) => void) | undefined,
2479+
sourceFiles: ReadonlyArray<SourceFile>,
2480+
) => void;
24772481

24782482
export class OperationCanceledException { }
24792483

@@ -3582,9 +3586,7 @@ namespace ts {
35823586
}
35833587

35843588
/* @internal */
3585-
export interface TypeMapper {
3586-
(t: TypeParameter): Type;
3587-
}
3589+
export type TypeMapper = (t: TypeParameter) => Type;
35883590

35893591
export const enum InferencePriority {
35903592
Contravariant = 1 << 0, // Inference from contravariant position
@@ -4192,9 +4194,7 @@ namespace ts {
41924194
}
41934195

41944196
/* @internal */
4195-
export interface HasInvalidatedResolution {
4196-
(sourceFile: Path): boolean;
4197-
}
4197+
export type HasInvalidatedResolution = (sourceFile: Path) => boolean;
41984198

41994199
export interface CompilerHost extends ModuleResolutionHost {
42004200
getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void, shouldCreateNewSourceFile?: boolean): SourceFile | undefined;

src/harness/harness.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -784,9 +784,15 @@ namespace Harness {
784784
? IO.newLine() + `//# sourceURL=${IO.resolvePath(tcServicesFileName)}`
785785
: "");
786786

787-
export interface SourceMapEmitterCallback {
788-
(emittedFile: string, emittedLine: number, emittedColumn: number, sourceFile: string, sourceLine: number, sourceColumn: number, sourceName: string): void;
789-
}
787+
export type SourceMapEmitterCallback = (
788+
emittedFile: string,
789+
emittedLine: number,
790+
emittedColumn: number,
791+
sourceFile: string,
792+
sourceLine: number,
793+
sourceColumn: number,
794+
sourceName: string,
795+
) => void;
790796

791797
// Settings
792798
export let userSpecifiedRoot = "";

src/server/editorServices.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ namespace ts.server {
7878

7979
export type ProjectServiceEvent = ProjectsUpdatedInBackgroundEvent | ConfigFileDiagEvent | ProjectLanguageServiceStateEvent | ProjectInfoTelemetryEvent;
8080

81-
export interface ProjectServiceEventHandler {
82-
(event: ProjectServiceEvent): void;
83-
}
81+
export type ProjectServiceEventHandler = (event: ProjectServiceEvent) => void;
8482

8583
export interface SafeList {
8684
[name: string]: { match: RegExp, exclude?: (string | number)[][], types?: string[] };

src/server/project.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,7 @@ namespace ts.server {
9898
getExternalFiles?(proj: Project): string[];
9999
}
100100

101-
export interface PluginModuleFactory {
102-
(mod: { typescript: typeof ts }): PluginModule;
103-
}
101+
export type PluginModuleFactory = (mod: { typescript: typeof ts }) => PluginModule;
104102

105103
/**
106104
* The project root can be script info - if root is present,

src/services/formatting/ruleOperationContext.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
namespace ts.formatting {
55

66
export class RuleOperationContext {
7-
private readonly customContextChecks: { (context: FormattingContext): boolean; }[];
7+
private readonly customContextChecks: ((context: FormattingContext) => boolean)[];
88

9-
constructor(...funcs: { (context: FormattingContext): boolean; }[]) {
9+
constructor(...funcs: ((context: FormattingContext) => boolean)[]) {
1010
this.customContextChecks = funcs;
1111
}
1212

tests/baselines/reference/api/tsserverlibrary.d.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,9 +1623,7 @@ declare namespace ts {
16231623
fileExists(path: string): boolean;
16241624
readFile(path: string): string | undefined;
16251625
}
1626-
interface WriteFileCallback {
1627-
(fileName: string, data: string, writeByteOrderMark: boolean, onError: ((message: string) => void) | undefined, sourceFiles: ReadonlyArray<SourceFile>): void;
1628-
}
1626+
type WriteFileCallback = (fileName: string, data: string, writeByteOrderMark: boolean, onError: ((message: string) => void) | undefined, sourceFiles: ReadonlyArray<SourceFile>) => void;
16291627
class OperationCanceledException {
16301628
}
16311629
interface CancellationToken {
@@ -3095,9 +3093,7 @@ declare namespace ts {
30953093
function isGetAccessor(node: Node): node is GetAccessorDeclaration;
30963094
}
30973095
declare namespace ts {
3098-
interface ErrorCallback {
3099-
(message: DiagnosticMessage, length: number): void;
3100-
}
3096+
type ErrorCallback = (message: DiagnosticMessage, length: number) => void;
31013097
interface Scanner {
31023098
getStartPos(): number;
31033099
getToken(): SyntaxKind;
@@ -7144,11 +7140,9 @@ declare namespace ts.server {
71447140
create(createInfo: PluginCreateInfo): LanguageService;
71457141
getExternalFiles?(proj: Project): string[];
71467142
}
7147-
interface PluginModuleFactory {
7148-
(mod: {
7149-
typescript: typeof ts;
7150-
}): PluginModule;
7151-
}
7143+
type PluginModuleFactory = (mod: {
7144+
typescript: typeof ts;
7145+
}) => PluginModule;
71527146
/**
71537147
* The project root can be script info - if root is present,
71547148
* or it could be just normalized path if root wasnt present on the host(only for non inferred project)
@@ -7418,9 +7412,7 @@ declare namespace ts.server {
74187412
readonly dts: number;
74197413
}
74207414
type ProjectServiceEvent = ProjectsUpdatedInBackgroundEvent | ConfigFileDiagEvent | ProjectLanguageServiceStateEvent | ProjectInfoTelemetryEvent;
7421-
interface ProjectServiceEventHandler {
7422-
(event: ProjectServiceEvent): void;
7423-
}
7415+
type ProjectServiceEventHandler = (event: ProjectServiceEvent) => void;
74247416
interface SafeList {
74257417
[name: string]: {
74267418
match: RegExp;

tests/baselines/reference/api/typescript.d.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,9 +1623,7 @@ declare namespace ts {
16231623
fileExists(path: string): boolean;
16241624
readFile(path: string): string | undefined;
16251625
}
1626-
interface WriteFileCallback {
1627-
(fileName: string, data: string, writeByteOrderMark: boolean, onError: ((message: string) => void) | undefined, sourceFiles: ReadonlyArray<SourceFile>): void;
1628-
}
1626+
type WriteFileCallback = (fileName: string, data: string, writeByteOrderMark: boolean, onError: ((message: string) => void) | undefined, sourceFiles: ReadonlyArray<SourceFile>) => void;
16291627
class OperationCanceledException {
16301628
}
16311629
interface CancellationToken {
@@ -2758,9 +2756,7 @@ declare namespace ts {
27582756
let sys: System;
27592757
}
27602758
declare namespace ts {
2761-
interface ErrorCallback {
2762-
(message: DiagnosticMessage, length: number): void;
2763-
}
2759+
type ErrorCallback = (message: DiagnosticMessage, length: number) => void;
27642760
interface Scanner {
27652761
getStartPos(): number;
27662762
getToken(): SyntaxKind;

tslint.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@
7676
"arrow-return-shorthand": false,
7777
"ban-comma-operator": false,
7878
"ban-types": false,
79-
"callable-types": false,
8079
"forin": false,
8180
"member-access": false, // [true, "no-public"]
8281
"no-conditional-assignment": false,

0 commit comments

Comments
 (0)