-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Open
Labels
accepting prsGo ahead, send a pull request that resolves this issueGo ahead, send a pull request that resolves this issuerepo maintenancethings to do with maintenance of the repo, and not with code/docsthings to do with maintenance of the repo, and not with code/docs
Description
Suggestion
Coming over from #11617: it's not well-known that ts-api-utils provides a handful of shortcut/wrapper methods around TypeScript bitwise enums/flags. For example, this method:
function hasBaseTypes(type: ts.Type): type is ts.InterfaceType {
return (
(type.flags & ts.TypeFlags.Object) !== 0 &&
(((type as ts.ObjectType).objectFlags & ts.ObjectFlags.Interface) !==
0 ||
((type as ts.ObjectType).objectFlags & ts.ObjectFlags.Class) !== 0)
);
}...can be rewritten as:
function hasBaseTypes(type: ts.Type): type is ts.InterfaceType {
return (
tsutils.isObjectType(type) &&
tsutils.isObjectFlagSet(
type,
ts.ObjectFlags.Interface | ts.ObjectFlags.Class,
)
);
}Proposal: let's write a general-purpose lint rule that enforces the latter when possible?
Additional Info
Eventually this might make sense to move to https://github.com/eslint-community/eslint-plugin-eslint-plugin, perhaps.
💖
Metadata
Metadata
Assignees
Labels
accepting prsGo ahead, send a pull request that resolves this issueGo ahead, send a pull request that resolves this issuerepo maintenancethings to do with maintenance of the repo, and not with code/docsthings to do with maintenance of the repo, and not with code/docs