-
Notifications
You must be signed in to change notification settings - Fork 12.8k
isArrayType declared internally returns type is TypeReference
however the converse is not true
#55510
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
Comments
I don't understand; is this not just #55010, which you filed and we closed as working as intended? Is there any new info here? I don't see how adding an empty interface would help, either. |
In #55010, because the proposed solution was not safe/strictly correct, the issue was marked as working as intended. The solution proposed here is safe. Adding an empty interface helps because if |
I don't see how this is true. According to your definition every |
This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Oops. I didn't realize typescript treats two types as the same if they have the same structure. Adding a field to make |
We have many branded types internally; but I think it stands to be seen why this change really needs to be made and whether or not there's some bug this fixes or something. |
The motivation for fixing this bug is shown in the following example: if (typeChecker.isArrayType(type)) {
// complains that type is not TypeReference
typeChecker.getTypeArguments(type);
} Currently, either a cast needs to be performed or an extra check needs to be performed. Otherwise the internal declaration is not strictly correct but it hasn't caused any bugs that I know of. |
⚙ Compilation target
N/A
⚙ Library
N/A
Missing / Incorrect Definition
From
src/compiler/checker.ts
:This implies that if
isArrayType
returns false thentype
is not aTypeReference
which may not be the case as pointed out by #55010 (comment).If instead an interface ArrayType was added like so:
and
isArrayType
updated like so:Then the signature would be safe and correct. This will then allow the externally available compiler API to match the internal one. Currently because the internal signature of
isArrayType
is not safe the external signature instead is:Sample Code
Documentation Link
Continuation of #55010
The text was updated successfully, but these errors were encountered: