Refresh is not really default true for thin instances methods

Kind of minor here, but doc on thin instances says that the refresh arg for three methods is default true.

The code comments also say “default true”. It is neither default true, nor optional at typescript level, which for a boolean is default false. I will be switching the faster method, but just using these to get my pattern right. Sure others will be doing the same. While minor, I could not get anything to show, which was puzzling. Think you want to get that corrected.

Actually the default value is true, for eg:

Mesh.prototype.thinInstanceAdd = 
    function(matrix: DeepImmutableObject<Matrix> | Array<DeepImmutableObject<Matrix>>,
           refresh: boolean = true): number {

The problem is that it is declared in an interface and it seems you can’t define default values there:

export interface Mesh {
    thinInstanceAdd(matrix: DeepImmutableObject<Matrix> | Array<DeepImmutableObject<Matrix>>,
            refresh: boolean): number;

So in Javascript it is indeed optional and the default is true, but in TS it is not optional.

I don’t know if there’s a way around this: @Deltakosh or @sebavan or @RaananW?

Maybe just doc note, and especially in code comments for intellisense.

Flag it as refresh?: number maybe?

The problem is with the default value:

thinInstanceAdd(matrix: DeepImmutableObject<Matrix> | Array<DeepImmutableObject<Matrix>>, 
         refresh?: boolean = true): number;

is not valid in an interface, I get an error “A parameter initializer is only allowed in a function or constructor implementation”. Using number instead of boolean fails in the same way.

No default values in interfaces. The only hack is to force it to be true | boolean , but this will probably create some confusion. And I’m not sure if it will bring any true benefit.
If the value is set in code to true, I guess the docs is the best way to go. And to always keep in mind to force “false” as default value in the future (even when it’s really confusing :wink:)

Yup just put the ? in the interface and default value in the implementation It will result in the behavior you want :slight_smile: