# CSG2 should return CSG2 type instead of any

**URL:** <https://forum.babylonjs.com/t/csg2-should-return-csg2-type-instead-of-any/54897>\
**Category:** Completed Features\
**Tags:** typescript, csg, csg2\
**Created:** [November 21, 2024, 12:42am UTC](https://forum.babylonjs.com/t/csg2-should-return-csg2-type-instead-of-any/54897 "2024-11-21T00:42:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kzhsw](https://avatars.discourse-cdn.com/v4/letter/k/848f3c/32.png) [@kzhsw](https://forum.babylonjs.com/u/kzhsw)\
**Post date:** [November 21, 2024, 12:42am UTC](https://forum.babylonjs.com/t/csg2-should-return-csg2-type-instead-of-any/54897/1 "2024-11-21T00:42:16Z")

</div>

Version: 7.34.4

## Background

Currently `CSG2.FromMesh` and other CSG2 methods return `any` type, makes it harder to inference type of returned value, and make it harder for devs to get type hints compared to the old CSG.

The `CSG2.FromMesh`:

> <https://github.com/BabylonJS/Babylon.js/blob/eb9bde27d42dd9412900e94190ca84cb4703de4a/packages/dev/core/src/Meshes/csg2.ts#L398>

The `CSG.FromMesh`:

> <https://github.com/BabylonJS/Babylon.js/blob/eb9bde27d42dd9412900e94190ca84cb4703de4a/packages/dev/core/src/Meshes/csg.ts#L518>

## Proposal

Make user-facing CSG2 methods return CSG2 type instead of `any`.

## Risks

Since CSG2 is already released with `any` type, narrowing the type to `CSG2` could be breaking for typescript users.

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [November 21, 2024, 10:48am UTC](https://forum.babylonjs.com/t/csg2-should-return-csg2-type-instead-of-any/54897/2 "2024-11-21T10:48:11Z")

</div>

CC @Deltakosh , I don’t see why it would be a problem doing that, but he would probably know better, as he built it 🙂

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [November 21, 2024, 4:05pm UTC](https://forum.babylonjs.com/t/csg2-should-return-csg2-type-instead-of-any/54897/3 "2024-11-21T16:05:48Z")

</div>

No problem at all and probably an oversight on my side  
Please do a PR @kzhsw

---

<div class="post-metadata">

**Author:** ![kzhsw](https://avatars.discourse-cdn.com/v4/letter/k/848f3c/32.png) [@kzhsw](https://forum.babylonjs.com/u/kzhsw)\
**Post date:** [November 22, 2024, 5:18am UTC](https://forum.babylonjs.com/t/csg2-should-return-csg2-type-instead-of-any/54897/4 "2024-11-22T05:18:24Z")

</div>

> <https://github.com/BabylonJS/Babylon.js/pull/15873>
>
> \## Background
> 
> Currently \`CSG2.FromMesh\` return \`any\` type, makes it harder to… inference type of returned value, and make it harder for devs to get type hints compared to the old CSG.
> After looking into the \[doc\](https://doc.babylonjs.com/typedoc/classes/BABYLON.CSG2), \`FromVertexData\` and other instance methods implicitly return \`CSG2\` type.
> 
> \## Proposal
> 
> Make \`CSG2.FromMesh\` method return \`CSG2\` type instead of any.
> 
> \## Risks
> 
> Since CSG2 is already released with any type, narrowing the type to CSG2 could be breaking for typescript users.
> 
> \## References
> 
> Forum post: \<https://forum.babylonjs.com/t/csg2-should-return-csg2-type-instead-of-any/54897\>
