Fix RouteNode type error #17
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem Description:
interface RouteNode extends RouteObject
The original code
RouteNode
directly inheritsRouteObject
, and an error will be reported: An interface can only extend the object type or the intersection of object types using static known members. ts(2312)Problem causes:
RouteObject
is a dynamic type:IndexRouteObject | NonIndexRouteObject
It is not a definite static type and therefore cannot be directly inherited
Solution:
Declare certain types for
IndexRouteObject
andNonIndexRouteObject
respectively:IndexRouteNode
andNonIndexRouteNode
Re-declare the dynamic type:
type RouteNode = IndexRouteNode | NonIndexRouteNode
问题描述:
interface RouteNode extends RouteObject
原代码
RouteNode
直接继承了RouteObject
,会报错:接口只能扩展使用静态已知成员的对象类型或对象类型的交集。ts(2312)问题原因:
RouteObject
是一个动态类型:IndexRouteObject | NonIndexRouteObject
它不是一个确定的静态类型,因此不能够被直接继承
解决方案:
对
IndexRouteObject
和NonIndexRouteObject
分别声明确定的类型:IndexRouteNode
和NonIndexRouteNode
再声明动态类型:
type RouteNode = IndexRouteNode | NonIndexRouteNode