Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: supports the issues/331 mentioned in points 2, 3, 4 #332

Merged
merged 6 commits into from
Sep 3, 2024

Conversation

lv-z-l
Copy link
Contributor

@lv-z-l lv-z-l commented Sep 2, 2024

  1. Component Object、Array 的 property支持通过 as 明确指定property的类型
  2. 支持Component 传自定义属性
  3. Component 当组件无 properties 选项时,xxx未在 data 中声明,this.data.xxx 不报 TS2339 error 的问题

@lv-z-l lv-z-l changed the title supports the issues/331 mentioned in points 2, 3, 4 feat: supports the issues/331 mentioned in points 2, 3, 4 Sep 2, 2024
@Mister-Hope
Copy link
Contributor

lgtm

types/wx/lib.wx.component.d.ts Outdated Show resolved Hide resolved
types/wx/lib.wx.component.d.ts Outdated Show resolved Hide resolved
test/component.test.ts Outdated Show resolved Hide resolved
types/wx/lib.wx.component.d.ts Outdated Show resolved Hide resolved
@SgLy SgLy merged commit 0a76c78 into wechat-miniprogram:master Sep 3, 2024
1 check passed
@yangmingshan
Copy link
Contributor

yangmingshan commented Oct 4, 2024

Component Object、Array 的 property支持通过 as 明确指定property的类型

我觉得没必要限制于 Object 跟 Array,Number 跟 String 也可以通过 as 指定更加准确的类型。

Component({
  properties: {
    num: {
      type: Number,
      value: 0 as 0 | 1
    },
    str: {
      type: String,
      value: 'foo' as 'foo' | 'bar'
    }
  }
})

可以修改为:

- type ArrayOrObject = ArrayConstructor | ObjectConstructor
- type FullPropertyToData<T extends AllFullProperty> = T['type'] extends ArrayOrObject ? unknown extends T['value'] ? ValueType<T['type']> : T['value'] : ValueType<T['type']>
+ type FullPropertyToData<T extends AllFullProperty> = T['type'] extends null | BooleanConstructor ? ValueType<T['type']> : unknown extends T['value'] ? ValueType<T['type']> : T['value']

@lv-z-l @Mister-Hope @SgLy 你们觉得呢?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants