{"id":297650,"date":"2021-01-18T09:29:36","date_gmt":"2021-01-18T01:29:36","guid":{"rendered":"http:\/\/4563.org\/?p=297650"},"modified":"2021-01-18T09:29:36","modified_gmt":"2021-01-18T01:29:36","slug":"typescript-%e7%9a%84%e6%b3%9b%e5%9e%8b%e5%8f%82%e6%95%b0%e5%bf%85%e9%a1%bb%e8%a6%81%e4%b9%88%e4%b8%8d%e5%a1%ab%e8%a6%81%e4%b9%88%e5%a1%ab%e5%ae%8c%e6%95%b4%ef%bc%9f%e8%bf%99%e7%a7%8d%e6%83%85%e5%86%b5","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=297650","title":{"rendered":"Typescript \u7684\u6cdb\u578b\u53c2\u6570\u5fc5\u987b\u8981\u4e48\u4e0d\u586b\u8981\u4e48\u586b\u5b8c\u6574\uff1f\u8fd9\u79cd\u60c5\u51b5\u600e\u4e48\u5904\u7406\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  Typescript \u7684\u6cdb\u578b\u53c2\u6570\u5fc5\u987b\u8981\u4e48\u4e0d\u586b\u8981\u4e48\u586b\u5b8c\u6574\uff1f\u8fd9\u79cd\u60c5\u51b5\u600e\u4e48\u5904\u7406\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : love <\/span>  <span><i><\/i> 6<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<pre><code>class Model {     a!: number     b!: string }  class ModelB extends Model {     c!: boolean }  declare function getData&lt;R, M extends Model&gt;(m: M, field: keyof M): R  \/\/ \u8fd9\u91cc\u6211\u5e0c\u671b M \u53c2\u6570\u81ea\u52a8\u53d6\u81ea\u7b2c\u4e00\u4e2a\u53c2\u6570\uff0c\u7136\u540e\u53ef\u4ee5\u6307\u5b9a\u4e00\u4e2a\u8fd4\u56de\u503c\u7c7b\u578b\u4e3a number \u3002 \/\/ \u53ef\u662f\u4f3c\u4e4e\u505a\u4e0d\u5230\uff1f\u62a5\u7f3a\u4e00\u4e2a\u6cdb\u578b\u53c2\u6570\u9519\u8bef let r = getData&lt;number&gt;(new ModelB(), 'c') <\/code><\/pre>\n<p>Playground<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>1<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"5037705\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : codehz <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             https:\/\/github.com\/Microsoft\/TypeScript\/issues\/26242<br \/>\u6709\u63d0\u6848\uff0c\u4f46\u6ca1\u63a5\u53d7                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>Typescript \u7684\u6cdb\u578b\u53c2\u6570\u5fc5&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\/297650"}],"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=297650"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/297650\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=297650"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=297650"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=297650"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}