File tree Expand file tree Collapse file tree 2 files changed +47
-2
lines changed
Expand file tree Collapse file tree 2 files changed +47
-2
lines changed Original file line number Diff line number Diff line change 1- import { expectType } from 'tsd'
1+ import { expectError , expectType } from 'tsd'
22
33// https://github.com/wechat-miniprogram/api-typings/issues/11
44expectType < string > ( wx . env . USER_DATA_PATH )
@@ -443,3 +443,48 @@ import WX = WechatMiniprogram
443443 expectType < number > ( offscreenCanvas . height )
444444 expectType < number > ( offscreenCanvas . width )
445445}
446+
447+ // https://github.com/wechat-miniprogram/api-typings/issues/332
448+ {
449+ Component ( {
450+ data : {
451+ a : ''
452+ } ,
453+ methods : {
454+ test ( ) {
455+ expectError < any > ( this . data . xxx )
456+ } ,
457+ }
458+ } )
459+ }
460+
461+ {
462+ interface Foo {
463+ f : string
464+ }
465+
466+ Component ( {
467+ _timer : '' ,
468+ properties : {
469+ bar : {
470+ type : Object ,
471+ value : { f : '' } as Foo ,
472+ observer ( ) { }
473+ } ,
474+ foo : {
475+ type : Array ,
476+ value : [ ] as Foo [ ] ,
477+ }
478+ } ,
479+ methods : {
480+ getData ( ) {
481+ return this . data . foo
482+ } ,
483+ test ( ) {
484+ expectType < Foo > ( this . data . bar )
485+ expectType < Foo [ ] > ( this . getData ( ) )
486+ expectType < string > ( this . _timer )
487+ } ,
488+ }
489+ } )
490+ }
Original file line number Diff line number Diff line change @@ -70,7 +70,7 @@ declare namespace WechatMiniprogram.Component {
7070 <
7171 TData extends DataOption ,
7272 // 给泛型默认值,避免出现当组件无 properties 选项时
73- // 当xxx未在 data 中声明,this.data.xxx 为 any 的问题。
73+ // 当xxx未在 data 中声明,this.data.xxx 为 any 且不报 TS2339 error 的问题。
7474 TProperty extends PropertyOption = { } ,
7575 TMethod extends MethodOption = { } ,
7676 TCustomInstanceProperty extends IAnyObject = { } ,
You can’t perform that action at this time.
0 commit comments