eslint-plugin-next-route-params
Version:
eslint rule to enforce correct route parameters for Next.js
23 lines (22 loc) • 1.01 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.unwrapPromise = unwrapPromise;
const utils_1 = require("@typescript-eslint/utils");
function unwrapPromise(potentialPromise, fn) {
if (potentialPromise != null &&
potentialPromise.type === utils_1.AST_NODE_TYPES.TSPropertySignature &&
potentialPromise.typeAnnotation?.typeAnnotation.type ===
utils_1.AST_NODE_TYPES.TSTypeReference) {
const typeName = potentialPromise.typeAnnotation.typeAnnotation.typeName;
if (typeName.type === utils_1.AST_NODE_TYPES.Identifier &&
typeName.name === "Promise") {
const firstParam = potentialPromise.typeAnnotation.typeAnnotation.typeArguments?.params[0];
const promiseType = fn != null ? fn(firstParam) : firstParam;
return {
isPromise: true,
promiseType: promiseType,
};
}
}
return { isPromise: false, promiseType: undefined };
}