-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Add the .getNonPrimitiveType()
method to the TypeChecker
#61562
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
base: main
Are you sure you want to change the base?
Conversation
The TypeScript team hasn't accepted the linked issue #61517. If you can get it accepted, this PR will have a better chance of being reviewed. |
Looks like you're introducing a change to the public API surface area. If this includes breaking changes, please document them on our wiki's API Breaking Changes page. Also, please make sure @DanielRosenwasser and @RyanCavanaugh are aware of the changes, just as a heads up. |
. getNonPrimitiveType()
method to the TypeChecker
.getNonPrimitiveType()
method to the TypeChecker
What's the use for this one? I can understand the rest, but this seems like a weird one to need. |
is there any advantage in naming the method |
I was explaining my use case in the issue: The project I am working on is using TypeScript programatically. The And here is the workaround I have at the moment (obviously, this cannot work with TypeScript 7 anymore): const nonPrimitiveType = { flags: this.#compiler.TypeFlags.NonPrimitive } as ts.Type; // the intrinsic 'object' type
if (!typeChecker.isTypeAssignableTo(sourceType, nonPrimitiveType)) {
// skipped
}; |
@ritschwumm See the issue, please. The naming was discussed there. |
@jakebailey I agree, it might seem so. In a way I could use overloads and the one which requires the input to be an object could have A user might add For example, current I can easily validate that the provided type is a function ( Please, take into account the type provided by a user can be a union or an intersection. Hence looking for the if (!typeChecker.isTypeAssignableTo(sourceType, typeChecker.getNonPrimitiveType())) {
// skipped
}; |
Fixes #61517
This PR is adding the
.getNonPrimitiveType()
method to theTypeChecker
. Similar to methods like.getAnyType()
or.getUndefinedType()
, the returned value of.getNonPrimitiveType()
is theType
of the intrinsicobject
type.A comment is included to explain what the method does. I think, it might not be clear that
NonPrimitive
is actually the intrinsicobject
type.I updated the
tests/baselines/reference/api/typescript.d.ts
file. Is that enough for testing, perhaps? I looked around, but can’t find any explicit tests for other methods of theTypeChecker
.