weixin_39761880
weixin_39761880
2020-12-08 20:30

Using shorthands with TypeScript

When using with TypeScript

ts
Swal.fire(<p>Shorthand works too</p>)

produces this error:

image

Which is correct per sweetalert2's types:

ts
function fire(title?: string, message?: string, icon?: SweetAlertIcon): Promise<sweetalertresult>;
</sweetalertresult>

The first param title is string and passing <p>Shorthand works too</p> should produce an error.

Should we deprecate shorthands or somehow support passing Element shorthands? What do you think about this

该提问来源于开源项目:sweetalert2/sweetalert2-react-content

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

4条回答

  • weixin_39761880 weixin_39761880 5月前

    Can't reproduce this issue anymore, shorthands seem to work as expected:

    image

    点赞 评论 复制链接分享
  • weixin_39761558 weixin_39761558 5月前

    Should we deprecate shorthands or somehow support passing Element shorthands? What do you think about this

    I don't think we should ever downgrade the actual capabilities of a library in order to match typings. It should be the other way around; the typings should be made to match the actual types of the library.

    点赞 评论 复制链接分享
  • weixin_39761880 weixin_39761880 5月前

    Done, thank you for the feedback!

    sweetalert2-react-content is used in sweetalert2-webpack-demo now: https://github.com/sweetalert2/sweetalert2-webpack-demo/commit/962f5f6e18948d85883a0b7ba5d83c267aa39f37 :tada:

    点赞 评论 复制链接分享
  • weixin_39761880 weixin_39761880 5月前

    Reopening this issue as https://github.com/sweetalert2/sweetalert2/pull/1804 brought the regression described in https://github.com/sweetalert2/sweetalert2/issues/1822

    This issue should be fixed here.

    点赞 评论 复制链接分享

相关推荐