Add the .getNonPrimitiveType() method to the TypeChecker#61562
Add the .getNonPrimitiveType() method to the TypeChecker#61562jakebailey merged 2 commits intomicrosoft:mainfrom mrazauskas:main
.getNonPrimitiveType() method to the TypeChecker#61562Conversation
|
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 theTypeof the intrinsicobjecttype.A comment is included to explain what the method does. I think, it might not be clear that
NonPrimitiveis actually the intrinsicobjecttype.I updated the
tests/baselines/reference/api/typescript.d.tsfile. Is that enough for testing, perhaps? I looked around, but can’t find any explicit tests for other methods of theTypeChecker.