Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] prop-types: Support typescript props interface extension and TSTypeAliasDeclaration #2721

Merged
merged 1 commit into from Aug 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
72 changes: 71 additions & 1 deletion lib/util/ast.js
Expand Up @@ -201,6 +201,66 @@ function unwrapTSAsExpression(node) {
return node;
}

function isTSTypeReference(node) {
if (!node) return false;
const nodeType = node.type;
return nodeType === 'TSTypeReference';
}

function isTSTypeAnnotation(node) {
if (!node) return false;
const nodeType = node.type;
return nodeType === 'TSTypeAnnotation';
}

function isTSTypeLiteral(node) {
if (!node) return false;
const nodeType = node.type;
return nodeType === 'TSTypeLiteral';
}

function isTSIntersectionType(node) {
if (!node) return false;
const nodeType = node.type;
return nodeType === 'TSIntersectionType';
}

function isTSInterfaceHeritage(node) {
if (!node) return false;
const nodeType = node.type;
return nodeType === 'TSInterfaceHeritage';
}

function isTSInterfaceDeclaration(node) {
if (!node) return false;
const nodeType = node.type;
return nodeType === 'TSInterfaceDeclaration';
}

function isTSTypeAliasDeclaration(node) {
if (!node) return false;
const nodeType = node.type;
return nodeType === 'TSTypeAliasDeclaration';
}

function isTSParenthesizedType(node) {
if (!node) return false;
const nodeType = node.type;
return nodeType === 'TSTypeAliasDeclaration';
}

function isTSFunctionType(node) {
if (!node) return false;
const nodeType = node.type;
return nodeType === 'TSFunctionType';
}

function isTSTypeQuery(node) {
if (!node) return false;
const nodeType = node.type;
return nodeType === 'TSTypeQuery';
}

module.exports = {
findReturnStatement,
getFirstNodeInLine,
Expand All @@ -213,5 +273,15 @@ module.exports = {
isFunction,
isFunctionLikeExpression,
isNodeFirstInLine,
unwrapTSAsExpression
unwrapTSAsExpression,
isTSTypeReference,
isTSTypeAnnotation,
isTSTypeLiteral,
isTSIntersectionType,
isTSInterfaceHeritage,
isTSInterfaceDeclaration,
isTSTypeAliasDeclaration,
isTSParenthesizedType,
isTSFunctionType,
isTSTypeQuery
};