{"id":277967,"date":"2021-01-14T16:02:38","date_gmt":"2021-01-14T08:02:38","guid":{"rendered":"http:\/\/4563.org\/?p=277967"},"modified":"2021-01-14T16:02:38","modified_gmt":"2021-01-14T08:02:38","slug":"typescript-%e8%83%bd%e5%90%a6%e8%be%be%e6%88%90%e8%bf%99%e4%b8%aa%e6%95%88%e6%9e%9c%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=277967","title":{"rendered":"Typescript \u80fd\u5426\u8fbe\u6210\u8fd9\u4e2a\u6548\u679c\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  Typescript \u80fd\u5426\u8fbe\u6210\u8fd9\u4e2a\u6548\u679c\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : weijar <\/span>  <span><i><\/i> 0<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<pre><code>class Model {     setProps (props: any) { \/\/ \u8fd9\u91cc\u7684 any \u8981\u6539\u6210\u9650\u5236\u7c7b\u7684\u5c5e\u6027       Object.assign(this, props)     } }  class User extends Model {     id!: string     name!: string }  const user = new User() user.setProps({ name: 'Jack', age: 100 }) \/\/ \u8fd9\u91cc age \u4e0d\u662f User \u7684\u5c5e\u6027\uff0c\u80fd\u5426\u6709\u529e\u6cd5\u62a5\u9519\uff1f <\/code><\/pre>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>8<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4924839\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Vegetable <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             class User extends Model {<br \/> id!: string<br \/> name!: string<br \/> setProps(props: { name: string, id: string }) {<br \/> super.setProps(props)<br \/> }<\/p>\n<p>}                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4924840\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : weijar <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7b97\u4e86\uff0c\u81ea\u5df1\u627e\u5230\u7b54\u6848\u4e86<br \/>seProps&lt;T&gt; (this: T, data: Partial&lt;Exclude&lt;T, &#8216;id&#8217;&gt;&gt;)<\/p>\n<p>ts \u771f\u662f\u592a nb \u4e86                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4924841\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : weijar <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Vegetable \u4f60\u8fd9\u4e2a\u4e0d\u901a\u7528\u554a                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4924842\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Vegetable <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @weijar \u662f\u633a\u725b\u903c&#8230;                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4924843\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : weijar <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5367\u69fd\uff0c\u6709\u65b0\u95ee\u9898\u4e86\uff0c\u8fd9\u62db\u5728 constructor \u4e0d\u597d\u4f7f\uff1f\u600e\u4e48\u529e\uff1f<br \/>new User({ age: 100 }) \/\/ \u5982\u679c setProps \u8981\u6539\u6210\u5728\u6784\u9020\u5668\u4e2d\u4f20\u5165                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4924844\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : SilencerL <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             class Model {<br \/> setProps?&lt;T&gt;(props: T) {<br \/> Object.assign(this, props)<br \/> }<br \/>}                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4924845\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : weijar <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7ed3\u8d34\uff1a \u5728\u6784\u9020\u5668\u4e0a\u76ee\u524d\u662f\u4e0d\u53ef\u80fd\u5b9e\u73b0\u7684<br \/>https:\/\/github.com\/microsoft\/TypeScript\/issues\/40451                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4924846\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : meepo3927 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fde\u7eed\u81ea\u95ee\u81ea\u7b54\uff0c \u4e3b\u5b66\u4e60\u80fd\u529b\u8d85\u7fa4                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>Typescript \u80fd\u5426\u8fbe\u6210\u8fd9\u4e2a&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/277967"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=277967"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/277967\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=277967"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=277967"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=277967"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}