@vanta-inc/eslint-plugin-vanta
Version:
Custom ESLint rules for Vanta
37 lines (36 loc) • 1.05 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractNamedType = exports.isListType = void 0;
/**
* Given a TypeNode, determine whether it is a list type, ignoring
* nullability.
*/
var isListType = function (type) {
if (type.kind === "ListType") {
return true;
}
if (type.kind === "NonNullType") {
return exports.isListType(type.type);
}
return false;
};
exports.isListType = isListType;
/**
* Given a TypeNode, extract the base NamedType.
*
* ExtractNamedType strips off ListTypes and NonNullTypes –
* calling with the type T, T!, [T], [T!], [T!]! all return T.
*/
var extractNamedType = function (type) {
if (type.kind === "NamedType") {
return type;
}
if (type.kind === "ListType") {
return exports.extractNamedType(type.type);
}
if (type.kind === "NonNullType") {
return exports.extractNamedType(type.type);
}
throw new Error("Unsupported type: " + type);
};
exports.extractNamedType = extractNamedType;