wrec 0.35.1 → 0.35.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/scripts/lint.js +35 -8
package/package.json
CHANGED
package/scripts/lint.js
CHANGED
|
@@ -1602,6 +1602,23 @@ function requiresContextFunction(symbol, sourceFile) {
|
|
|
1602
1602
|
});
|
|
1603
1603
|
}
|
|
1604
1604
|
|
|
1605
|
+
// Returns whether a type represents an object-like value other than an array.
|
|
1606
|
+
function isNonArrayObjectLikeType(checker, type) {
|
|
1607
|
+
if (type.isUnion()) {
|
|
1608
|
+
return type.types.every(member => isNonArrayObjectLikeType(checker, member));
|
|
1609
|
+
}
|
|
1610
|
+
|
|
1611
|
+
if (type.isIntersection()) {
|
|
1612
|
+
return type.types.every(member => isNonArrayObjectLikeType(checker, member));
|
|
1613
|
+
}
|
|
1614
|
+
|
|
1615
|
+
return (
|
|
1616
|
+
Boolean(type.flags & (ts.TypeFlags.Object | ts.TypeFlags.NonPrimitive)) &&
|
|
1617
|
+
!checker.isArrayType(type) &&
|
|
1618
|
+
!checker.isTupleType(type)
|
|
1619
|
+
);
|
|
1620
|
+
}
|
|
1621
|
+
|
|
1605
1622
|
// Resolves a relative import path to an existing source file.
|
|
1606
1623
|
function resolveImportPath(baseDir, importPath) {
|
|
1607
1624
|
if (!importPath.startsWith('.')) return undefined;
|
|
@@ -1622,6 +1639,22 @@ function toUserFacingExpression(text) {
|
|
|
1622
1639
|
return text.replaceAll(WREC_REF_NAME, 'this');
|
|
1623
1640
|
}
|
|
1624
1641
|
|
|
1642
|
+
// Returns whether a static property config type is compatible with a declare type.
|
|
1643
|
+
function typeExpressionMatchesDeclaredType(
|
|
1644
|
+
checker,
|
|
1645
|
+
typeExpression,
|
|
1646
|
+
declaredTypeNode
|
|
1647
|
+
) {
|
|
1648
|
+
const declaredType = checker.getTypeFromTypeNode(declaredTypeNode);
|
|
1649
|
+
|
|
1650
|
+
if (typeExpressionKind(typeExpression) === 'Object') {
|
|
1651
|
+
return isNonArrayObjectLikeType(checker, declaredType);
|
|
1652
|
+
}
|
|
1653
|
+
|
|
1654
|
+
const runtimeType = checker.getTypeAtLocation(typeExpression);
|
|
1655
|
+
return checker.isTypeAssignableTo(runtimeType, declaredType);
|
|
1656
|
+
}
|
|
1657
|
+
|
|
1625
1658
|
// Classifies a constructor-based type expression by its identifier name.
|
|
1626
1659
|
function typeExpressionKind(expression) {
|
|
1627
1660
|
if (!expression) return undefined;
|
|
@@ -1776,11 +1809,7 @@ function validateDefaultValue(checker, typeExpression, valueExpression) {
|
|
|
1776
1809
|
}
|
|
1777
1810
|
|
|
1778
1811
|
if (typeKind === 'Object') {
|
|
1779
|
-
|
|
1780
|
-
Boolean(valueType.flags & ts.TypeFlags.Object) &&
|
|
1781
|
-
!checker.isArrayType(valueType) &&
|
|
1782
|
-
!checker.isTupleType(valueType);
|
|
1783
|
-
if (!isObjectLike) {
|
|
1812
|
+
if (!isNonArrayObjectLikeType(checker, valueType)) {
|
|
1784
1813
|
return {typeName: 'Object', valueTypeName};
|
|
1785
1814
|
}
|
|
1786
1815
|
}
|
|
@@ -1942,9 +1971,7 @@ function validatePropertyConfigs(
|
|
|
1942
1971
|
'Boolean, Number, String, Object, or Array'
|
|
1943
1972
|
);
|
|
1944
1973
|
} else if (declaredTypeNode) {
|
|
1945
|
-
|
|
1946
|
-
const declaredType = checker.getTypeFromTypeNode(declaredTypeNode);
|
|
1947
|
-
if (!checker.isTypeAssignableTo(runtimeType, declaredType)) {
|
|
1974
|
+
if (!typeExpressionMatchesDeclaredType(checker, typeExpression, declaredTypeNode)) {
|
|
1948
1975
|
findings.incompatibleDeclareTypes.push(
|
|
1949
1976
|
`property "${propName}" declare type ` +
|
|
1950
1977
|
`"${getPropertyTypeTextFromNode(sourceFile, declaredTypeNode)}" ` +
|