Problems of Object.defineProperty in typescript

clipboard.png
the above code will report an error in ts

[ts]
"{ enumerable: true; configurable: true; set: Function; get(): any; }" "PropertyDescriptor & ThisType<any>" 
  "{ enumerable: true; configurable: true; set: Function; get(): any; }" "PropertyDescriptor" 
    "set" 
      "Function" "(v: any) => void" 
        "Function" "(v: any): void" 

ask God to tell me how to solve the problem.

Mar.28,2021

I do not report errors here, for example, the following code

function fn() {
  console.log("test");
}
function a() {
  console.log("test");
}

Object.defineProperty({}, "test", {
  enumerable: true,
  configurable: true,
  set: a || fn,
  get() {
    return 5;
  }
});

if the value on set is not a function, an error will be reported.
you can release this.option.set and noop to see his type

Menu