import { expectType } from 'tsd' ; const ComputedComponent = Component as ComputedComponent ; ComputedComponent ( { properties : { a : String , } , data : { b : { c : 'test' , } , } , computed : { d ( ) { return 'test' ; } , } , methods : { f ( ) { expectType < string > ( this . data . d ) ; } , } , } ) ; type IMethods = { _setData : WechatMiniprogram . Component . InstanceMethods < { } > [ 'setData' ] ; } ; type ICustomProperty = { _originalSetData : WechatMiniprogram . Component . InstanceMethods < { } > [ 'setData' ] ; } ; Behavior < { } , { } , IMethods , ICustomProperty > ( { lifetimes : { created ( ) { this . _originalSetData = this . setData ; this . setData = this . _setData ; } , } , definitionFilter ( defFields ) { const computed = defFields . computed || { } ; const computedKeys = Object . keys ( computed ) ; const computedCache = { } ; const calcComputed = ( scope , insertToData ? ) => { const needUpdate = { } ; const data = ( defFields . data = defFields . data || { } ) ; for ( const key of computedKeys ) { const value = computed [ key ] . call ( scope ) ; if ( computedCache [ key ] !== value ) { needUpdate [ key ] = computedCache [ key ] = value ; } if ( insertToData ) data [ key ] = needUpdate [ key ] ; } return needUpdate ; } ; defFields . methods = defFields . methods || { } ; defFields . methods . _setData = function ( data , callback ? ) { const originalSetData = this . _originalSetData ; originalSetData . call ( this , data , callback ) ; const needUpdate = calcComputed ( this ) ; originalSetData . call ( this , needUpdate ) ; } ; calcComputed ( defFields , true ) ; } , } ) ;