{"id":4854,"date":"2023-01-05T11:03:30","date_gmt":"2023-01-05T03:03:30","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=4854"},"modified":"2023-01-05T11:03:30","modified_gmt":"2023-01-05T03:03:30","slug":"%e4%ba%86%e8%a7%a3typescript%e4%b8%ad%e5%9f%ba%e6%9c%ac%e9%a1%9e%e5%9e%8b%e7%9a%84%e5%8a%9f%e8%83%bd%e8%88%87%e6%87%89%e7%94%a8","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/typescript\/%e4%ba%86%e8%a7%a3typescript%e4%b8%ad%e5%9f%ba%e6%9c%ac%e9%a1%9e%e5%9e%8b%e7%9a%84%e5%8a%9f%e8%83%bd%e8%88%87%e6%87%89%e7%94%a8\/","title":{"rendered":"\u4e86\u89e3TypeScript\u4e2d\u57fa\u672c\u985e\u578b\u7684\u529f\u80fd\u8207\u61c9\u7528"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"TypeScript, Basic Types\"><\/p>\n<p>TypeScript \u662f\u4e00\u7a2e JavaScript \u7684\u8d85\u96c6\uff0c\u5b83\u64c1\u6709\u66f4\u591a\u7684\u529f\u80fd\uff0c\u5176\u4e2d\u5305\u62ec\u57fa\u672c\u985e\u578b(Basic Types)\u3002\u57fa\u672c\u985e\u578b\u662f TypeScript \u4e2d\u6700\u57fa\u672c\u7684\u985e\u578b\uff0c\u5b83\u5011\u53ef\u4ee5\u7528\u4f86\u5b9a\u7fa9\u8b8a\u6578\u7684\u503c\uff0c\u4e26\u4e14\u53ef\u4ee5\u7528\u4f86\u6aa2\u67e5\u8b8a\u6578\u7684\u503c\u662f\u5426\u7b26\u5408\u9810\u671f\u3002<\/p>\n<h2>TypeScript \u4e2d\u7684\u57fa\u672c\u985e\u578b<\/h2>\n<p>TypeScript \u4e2d\u7684\u57fa\u672c\u985e\u578b\u5305\u62ec\uff1a<strong>\u6578\u5b57(number)<\/strong>\u3001<strong>\u5b57\u4e32(string)<\/strong>\u3001<strong>\u5e03\u6797\u503c(boolean)<\/strong>\u3001<strong>\u9663\u5217(array)<\/strong>\u3001<strong>\u5143\u7d44(tuple)<\/strong>\u3001<strong>\u679a\u8209(enum)<\/strong>\u3001<strong>\u4efb\u610f\u503c(any)<\/strong>\u3001<strong>\u7a7a\u503c(void)<\/strong>\u3001<strong>null \u548c undefined<\/strong>\u3002<\/p>\n<h2>\u6578\u5b57(number)<\/h2>\n<p>\u6578\u5b57\u662f TypeScript \u4e2d\u6700\u5e38\u898b\u7684\u57fa\u672c\u985e\u578b\uff0c\u5b83\u53ef\u4ee5\u7528\u4f86\u5b9a\u7fa9\u6574\u6578\u6216\u6d6e\u9ede\u6578\u3002\u4f8b\u5982\uff1a<\/p>\n<pre class=\"brush: typescript\">\nlet num1: number = 10;\nlet num2: number = 3.14;\n<\/pre>\n<h2>\u5b57\u4e32(string)<\/h2>\n<p>\u5b57\u4e32\u662f TypeScript \u4e2d\u7528\u4f86\u8868\u793a\u6587\u5b57\u7684\u57fa\u672c\u985e\u578b\uff0c\u5b83\u53ef\u4ee5\u7528\u4f86\u5b9a\u7fa9\u5b57\u4e32\u5e38\u91cf\u6216\u8b8a\u6578\u3002\u4f8b\u5982\uff1a<\/p>\n<pre class=\"brush: typescript\">\nlet str1: string = 'Hello World';\nlet str2: string = \"Hello TypeScript\";\n<\/pre>\n<h2>\u5e03\u6797\u503c(boolean)<\/h2>\n<p>\u5e03\u6797\u503c\u662f TypeScript \u4e2d\u7528\u4f86\u8868\u793a\u771f\u5047\u7684\u57fa\u672c\u985e\u578b\uff0c\u5b83\u53ef\u4ee5\u7528\u4f86\u5b9a\u7fa9\u5e03\u6797\u5e38\u91cf\u6216\u8b8a\u6578\u3002\u4f8b\u5982\uff1a<\/p>\n<pre class=\"brush: typescript\">\nlet isTrue: boolean = true;\nlet isFalse: boolean = false;\n<\/pre>\n<h2>\u9663\u5217(array)<\/h2>\n<p>\u9663\u5217\u662f TypeScript \u4e2d\u7528\u4f86\u8868\u793a\u4e00\u7d44\u76f8\u540c\u985e\u578b\u7684\u8cc7\u6599\u7684\u57fa\u672c\u985e\u578b\uff0c\u5b83\u53ef\u4ee5\u7528\u4f86\u5b9a\u7fa9\u9663\u5217\u5e38\u91cf\u6216\u8b8a\u6578\u3002\u4f8b\u5982\uff1a<\/p>\n<pre class=\"brush: typescript\">\nlet arr1: number[] = [1, 2, 3];\nlet arr2: string[] = ['a', 'b', 'c'];\n<\/pre>\n<h2>\u5143\u7d44(tuple)<\/h2>\n<p>\u5143\u7d44\u662f TypeScript \u4e2d\u7528\u4f86\u8868\u793a\u4e00\u7d44\u4e0d\u540c\u985e\u578b\u7684\u8cc7\u6599\u7684\u57fa\u672c\u985e\u578b\uff0c\u5b83\u53ef\u4ee5\u7528\u4f86\u5b9a\u7fa9\u5143\u7d44\u5e38\u91cf\u6216\u8b8a\u6578\u3002\u4f8b\u5982\uff1a<\/p>\n<pre class=\"brush: typescript\">\nlet tuple1: [string, number] = ['a', 1];\nlet tuple2: [boolean, string] = [true, 'b'];\n<\/pre>\n<h2>\u679a\u8209(enum)<\/h2>\n<p>\u679a\u8209\u662f TypeScript \u4e2d\u7528\u4f86\u8868\u793a\u4e00\u7d44\u6709\u540d\u7a31\u7684\u5e38\u91cf\u7684\u57fa\u672c\u985e\u578b\uff0c\u5b83\u53ef\u4ee5\u7528\u4f86\u5b9a\u7fa9\u679a\u8209\u5e38\u91cf\u6216\u8b8a\u6578\u3002\u4f8b\u5982\uff1a<\/p>\n<pre class=\"brush: typescript\">\nenum Color {Red, Green, Blue};\nlet c: Color = Color.Green;\n<\/pre>\n<h2>\u4efb\u610f\u503c(any)<\/h2>\n<p>\u4efb\u610f\u503c\u662f TypeScript \u4e2d\u7528\u4f86\u8868\u793a\u4efb\u4f55\u985e\u578b\u7684\u57fa\u672c\u985e\u578b\uff0c\u5b83\u53ef\u4ee5\u7528\u4f86\u5b9a\u7fa9\u4efb\u610f\u503c\u5e38\u91cf\u6216\u8b8a\u6578\u3002\u4f8b\u5982\uff1a<\/p>\n<pre class=\"brush: typescript\">\nlet any1: any = 10;\nlet any2: any = 'Hello';\nlet any3: any = true;\n<\/pre>\n<h2>\u7a7a\u503c(void)<\/h2>\n<p>\u7a7a\u503c\u662f TypeScript \u4e2d\u7528\u4f86\u8868\u793a\u6c92\u6709\u4efb\u4f55\u985e\u578b\u7684\u57fa\u672c\u985e\u578b\uff0c\u5b83\u53ef\u4ee5\u7528\u4f86\u5b9a\u7fa9\u7a7a\u503c\u5e38\u91cf\u6216\u8b8a\u6578\u3002\u4f8b\u5982\uff1a<\/p>\n<pre class=\"brush: typescript\">\nlet void1: void = undefined;\nlet void2: void = null;\n<\/pre>\n<h2>null \u548c undefined<\/h2>\n<p>null \u548c undefined \u662f TypeScript \u4e2d\u7528\u4f86\u8868\u793a\u7279\u6b8a\u503c\u7684\u57fa\u672c\u985e\u578b\uff0c\u5b83\u5011\u53ef\u4ee5\u7528\u4f86\u5b9a\u7fa9 null \u548c undefined \u5e38\u91cf\u6216\u8b8a\u6578\u3002\u4f8b\u5982\uff1a<\/p>\n<pre class=\"brush: typescript\">\nlet n1: null = null;\nlet u1: undefined = undefined;\n<\/pre>\n<p><!--more--><\/p>\n<p>\u7e3d\u7d50\u4f86\u8aaa\uff0cTypeScript \u4e2d\u7684\u57fa\u672c\u985e\u578b\u53ef\u4ee5\u7528\u4f86\u5b9a\u7fa9\u8b8a\u6578\u7684\u503c\uff0c\u4e26\u4e14\u53ef\u4ee5\u7528\u4f86\u6aa2\u67e5\u8b8a\u6578\u7684\u503c\u662f\u5426\u7b26\u5408\u9810\u671f\u3002\u5b83\u5011\u53ef\u4ee5\u5e6b\u52a9\u958b\u767c\u8005\u66f4\u597d\u5730\u7ba1\u7406\u7a0b\u5f0f\u78bc\uff0c\u4e26\u4e14\u53ef\u4ee5\u6e1b\u5c11\u7a0b\u5f0f\u78bc\u51fa\u932f\u7684\u6a5f\u6703\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981:TypeScript\u662f\u4e00\u7a2e\u5f37\u578b\u5225\u7684JavaScript\u8173\u672c\u8a9e\u8a00\uff0c\u5b83\u63d0\u4f9b\u4e86\u8c50\u5bcc\u7684\u57fa\u672c\u985e\u578b\uff0c\u53ef\u4ee5\u5e6b\u52a9\u958b\u767c\u8005\u66f4\u6709\u6548\u5730\u69cb\u5efa\u61c9\u7528\u7a0b\u5e8f\u3002\u672c\u6587\u5c07\u4ecb\u7d39TypeScript\u4e2d\u57fa\u672c\u985e\u578b\u7684\u529f\u80fd\uff0c\u4ee5\u53ca\u5982\u4f55\u4f7f\u7528\u5b83\u5011\u4f86\u69cb\u5efa\u61c9\u7528\u7a0b\u5e8f\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-4854","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-1gi","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/4854","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=4854"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/4854\/revisions"}],"predecessor-version":[{"id":4855,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/4854\/revisions\/4855"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=4854"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=4854"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=4854"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}