#Encapsulation best practices

1 messages · Page 1 of 1 (latest)

hybrid crypt
#

When making fields public everything works fine, but how should we handle encapsulation?
As an example, say I have a C# class:

public class MyClass
{
    public string name;
}```
Then declare the type:
```export declare type MyClass = {
    name: string
}```
If I want to encapsulate the field like this:
```[System.Serializable]
public class MyClass
{
    [SerializeField] string name;
    public string Name { get => name; }
}```
What would the TypeScript type declaration would look like?
safe flicker
#

So your goal would be to have a custom type with a getter only / private field?