Skip to main content
Version: 1.6.0

private

The decorator @private can be used on a top-level declaration to prevent a given value from being exported outside the compilation unit.

Consider the following contents of the file module-with-private.jsligo:

@private const stuff = 42;
@private const g = x => x * stuff;
const f = x => g(x) + 1; // exported by default

Then the following piece of code, in another file:

#import "gitlab-pages/docs/tezos/decorators/src/module-with-private.mligo" "ModuleWithPrivate"
const foo = ModuleWithPrivate.f(123); // = 5167
/*
The following lines cause errors because g and stuff are private:
const bad_1 = ModuleWithPrivate.g(123);
const bad_2 = ModuleWithPrivate.stuff;
*/