alibaba / formily

📱🚀 🧩 Cross Device & High Performance Normal Form/Dynamic(JSON Schema) Form/Form Builder -- Support React/React Native/Vue 2/Vue 3
https://formilyjs.org/
MIT License
11.48k stars 1.49k forks source link

[Bug Report] define方法,如何订阅私有属性 #3645

Closed franckXu closed 1 year ago

franckXu commented 1 year ago

Reproduction link

Edit on CodeSandbox

Steps to reproduce


import { define, observable } from "@formily/reactive";
class Todo {
  private loading: boolean;
  constructor() {
    define(this, {
      loading: observable.ref // <<< ts不允许annotations私有属性,,但我不想外部修改loading字段,
      // https://mobx.js.org/observable-state.html#limitations的第8点,有解决方法,formily/reactive有类似的实现吗?
// By default TypeScript will not allow you to annotate private fields. This can be overcome by explicitly passing the relevant 
// private fields as generic argument, like this: makeObservable<MyStore, "privateField" | "privateField2">(this, { privateField: 
// observable, privateField2: observable })
    });
  }
  fetch() {
    this.loading = true;
    // ......
    this.loading = false;
  }
}

What is expected?

What is actually happening?

Package

@formily/reactive@2.2.15


janryWang commented 1 year ago

不支持