{"id":5336,"date":"2023-01-05T12:28:40","date_gmt":"2023-01-05T04:28:40","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=5336"},"modified":"2023-01-05T12:28:40","modified_gmt":"2023-01-05T04:28:40","slug":"%e4%ba%86%e8%a7%a3typescript%e4%b8%ad%e7%9a%84null%e5%8a%9f%e8%83%bd","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/typescript\/%e4%ba%86%e8%a7%a3typescript%e4%b8%ad%e7%9a%84null%e5%8a%9f%e8%83%bd\/","title":{"rendered":"\u4e86\u89e3TypeScript\u4e2d\u7684null\u529f\u80fd"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"TypeScript, null\"><\/p>\n<h1>TypeScript \u4e2d\u7684 null<\/h1>\n<p>TypeScript \u662f\u4e00\u7a2e JavaScript \u7684\u8d85\u96c6\uff0c\u5b83\u63d0\u4f9b\u4e86\u66f4\u591a\u7684\u7279\u6027\uff0c\u4f8b\u5982\u985e\u578b\u6aa2\u67e5\u548c\u975c\u614b\u5206\u6790\u3002\u5728 TypeScript \u4e2d\uff0cnull \u662f\u4e00\u7a2e\u7279\u6b8a\u7684\u503c\uff0c\u5b83\u53ef\u4ee5\u7528\u4f86\u8868\u793a\u4e00\u500b\u7a7a\u7684\u503c\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u5728 TypeScript \u4e2d\uff0cnull \u662f\u4e00\u7a2e\u7279\u6b8a\u7684\u503c\uff0c\u5b83\u53ef\u4ee5\u7528\u4f86\u8868\u793a\u4e00\u500b\u7a7a\u7684\u503c\u3002\u5b83\u53ef\u4ee5\u7528\u4f86\u8868\u793a\u4e00\u500b\u672a\u5b9a\u7fa9\u7684\u503c\uff0c\u6216\u8005\u4e00\u500b\u672a\u77e5\u7684\u503c\u3002\u5b83\u4e5f\u53ef\u4ee5\u7528\u4f86\u8868\u793a\u4e00\u500b\u53ef\u80fd\u5b58\u5728\u7684\u503c\uff0c\u4f46\u662f\u5c1a\u672a\u78ba\u5b9a\u3002<\/p>\n<h2>null \u7684\u985e\u578b<\/h2>\n<p>\u5728 TypeScript \u4e2d\uff0cnull \u662f\u4e00\u7a2e\u7279\u6b8a\u7684\u503c\uff0c\u5b83\u7684\u985e\u578b\u662f <code>null<\/code>\u3002\u5b83\u53ef\u4ee5\u88ab\u8ce6\u4e88\u4efb\u4f55\u985e\u578b\uff0c\u4f46\u662f\u5b83\u672c\u8eab\u7684\u985e\u578b\u662f <code>null<\/code>\u3002<\/p>\n<pre class=\"brush: typescript\">\nlet x: number = null; \/\/ x \u7684\u985e\u578b\u662f null\n<\/pre>\n<h2>null \u7684\u6aa2\u67e5<\/h2>\n<p>\u5728 TypeScript \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>null<\/code> \u4f86\u6aa2\u67e5\u4e00\u500b\u8b8a\u6578\u662f\u5426\u70ba\u7a7a\u3002<\/p>\n<pre class=\"brush: typescript\">\nlet x: number | null = null;\n\nif (x === null) {\n    console.log(\"x is null\");\n}\n<\/pre>\n<h2>null \u7684\u8f49\u63db<\/h2>\n<p>\u5728 TypeScript \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>null<\/code> \u4f86\u5c07\u4e00\u500b\u8b8a\u6578\u5f9e\u4e00\u500b\u985e\u578b\u8f49\u63db\u70ba\u53e6\u4e00\u500b\u985e\u578b\u3002<\/p>\n<pre class=\"brush: typescript\">\nlet x: number | null = null;\nlet y: number = x as number; \/\/ y \u7684\u985e\u578b\u662f number\n<\/pre>\n<h2>null \u7684\u61c9\u7528<\/h2>\n<p>\u5728 TypeScript \u4e2d\uff0cnull \u53ef\u4ee5\u7528\u4f86\u8868\u793a\u4e00\u500b\u672a\u5b9a\u7fa9\u7684\u503c\uff0c\u6216\u8005\u4e00\u500b\u672a\u77e5\u7684\u503c\u3002\u5b83\u4e5f\u53ef\u4ee5\u7528\u4f86\u8868\u793a\u4e00\u500b\u53ef\u80fd\u5b58\u5728\u7684\u503c\uff0c\u4f46\u662f\u5c1a\u672a\u78ba\u5b9a\u3002\u5b83\u53ef\u4ee5\u7528\u4f86\u6aa2\u67e5\u4e00\u500b\u8b8a\u6578\u662f\u5426\u70ba\u7a7a\uff0c\u6216\u8005\u5c07\u4e00\u500b\u8b8a\u6578\u5f9e\u4e00\u500b\u985e\u578b\u8f49\u63db\u70ba\u53e6\u4e00\u500b\u985e\u578b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2TypeScript\u4e2d\u7684null\u529f\u80fd\uff0c\u4e86\u89e3null\u7684\u5b9a\u7fa9\u3001\u4f7f\u7528\u65b9\u6cd5\u3001\u548c\u5b83\u5728TypeScript\u4e2d\u7684\u61c9\u7528\u3002\u901a\u904e\u672c\u6587\uff0c\u4f60\u5c07\u5b78\u7fd2\u5230\u5982\u4f55\u5728TypeScript\u4e2d\u4f7f\u7528null\uff0c\u4ee5\u53ca\u5b83\u7684\u512a\u9ede\u548c\u7f3a\u9ede\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[187],"tags":[186],"class_list":["post-5336","post","type-post","status-publish","format-standard","hentry","category-typescript","tag-typescript"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1o4","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5336","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=5336"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5336\/revisions"}],"predecessor-version":[{"id":5337,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5336\/revisions\/5337"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=5336"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=5336"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=5336"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}