Currently, there is no way to enable strict object literal check besides the case when we pass the object to the function directly. It would be great to separate options of such builders into a separate interface in order to provide more flexibility for developers in terms of type declarations and at the same time keep our code base type safe
Welcome aboard!
I guess you can write:
const options: {
lines: Vector3[][];
updatable?: boolean;
instance?: Nullable<LinesMesh>;
colors?: Nullable<Color4[][]>;
useVertexAlpha?: boolean;
material?: Material
} = {
...
}
but I agree it is more cumbersome than having a specific type in the first place…
cc @RaananW and @sebavan to decide if this is something we should add (it’s not only line builders that take options but also many others…).
I am totally not against it . Makes sense to me.
A small note, TypeScript does allow you to do the following:
type CreateLineOptions = Parameters<typeof CreateLines>[0];
Didn’t know about the Parameters
utility type, looks neat, thanks!
Let me know if you need any help, I would love to contribute to such amazing project
If you want to submit the PR, we will be very happy to merge it!
Is there any way to do this in JavaScript?
What exactly are you referring to? types are not supported in javascript, the rest is already in javascript
I’m trying to develop an interactive app to teach Babyblon.js. I’d like to be able to get a list of the available options when creating an mesh or material to show to the user.
Is there any way to do that in JavaScript? If not I’ll just have to fallback to using a pre-written, hard-coded list.
I’m using JavaScript and I have very limited exposure to TypeScript.
Most IDEs support TSDoc for javascript as well. But this is a type/doc definition of a js object. if you are in vanilla js outside of an IDE you won’t be able to get the types. There is also no way to reverse-engineer this, sadly.
I thought this was the case.
Forgive my ignorance, but out of curiosity is Typescript compiled into JavaScript before deployment?
yes, tyepscript is just javascript with types (and some other wonderful goodies