{"id":3466,"date":"2024-11-10T17:16:40","date_gmt":"2024-11-10T09:16:40","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3466\/"},"modified":"2024-11-10T17:16:40","modified_gmt":"2024-11-10T09:16:40","slug":"%e5%ad%a6%e4%b9%a0-typescript-%e7%9a%84%e6%97%85%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3466\/","title":{"rendered":"\u5b66\u4e60 Typescript \u7684\u65c5\u7a0b"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173104176294941.jpg\" class=\"aligncenter\" title=\"\u5b66\u4e60 Typescript \u7684\u65c5\u7a0b\u63d2\u56fe\" alt=\"\u5b66\u4e60 Typescript \u7684\u65c5\u7a0b\u63d2\u56fe\" \/>\u5927\u5bb6\u597d\uff0c\u6211\u6700\u8fd1\u5f00\u59cb\u4e86\u6211\u7684  \u4e4b\u65c5\uff0c\u5e76\u901a\u8fc7\u7f16\u7a0b\u82f1\u96c4\u7684\u9ad8\u7ea7 web \u5f00\u53d1\u8bfe\u7a0b\u53d6\u5f97\u4e86\u8fdb\u6b65\u3002\u6211\u5bf9 typescript \u6709\u4e00\u4e9b\u57fa\u7840\u77e5\u8bc6\uff0c\u4f46\u6ca1\u6709\u6df1\u5165\u63a2\u7d22\u3002\u6211\u7684\u8bfe\u7a0b\u4ece\u6df1\u5165\u7814\u7a76 typescript \u5f00\u59cb\u3002\u4e00\u5468\u8fc7\u53bb\u4e86\uff0c\u6211\u7684\u5b66\u4e60\u6709\u4e86\u5f88\u5927\u7684\u8fdb\u6b65\u3002\u4ee5\u4e0b\u662f\u6211\u6240\u638c\u63e1\u7684\u5173\u952e\u6982\u5ff5\u7684\u7b80\u5316\u6982\u8ff0\u3002<\/p>\n<h2> <strong>typescript \u5c31\u50cf javascript\uff0c\u4f46\u5177\u6709\u8d85\u80fd\u529b\uff01<\/strong> <\/h2>\n<p>typescript \u662f javascript \u7684\u8d85\u96c6\uff0c\u4e3a\u8be5\u8bed\u8a00\u6dfb\u52a0\u4e86\u53ef\u9009\u7684\u9759\u6001\u7c7b\u578b\u3002\u8fd9\u610f\u5473\u7740\u60a8\u53ef\u4ee5\u58f0\u660e\u53d8\u91cf\u3001\u51fd\u6570\u53c2\u6570\u548c\u8fd4\u56de\u503c\u7684\u7c7b\u578b\uff0c\u8fd9\u6709\u52a9\u4e8e\u5728\u5f00\u53d1\u8fc7\u7a0b\u7684\u65e9\u671f\u53d1\u73b0\u6f5c\u5728\u7684\u9519\u8bef\u3002<br \/><strong>\u4f7f\u7528 typescript \u7684\u597d\u5904<\/strong><\/p>\n<ul>\n<li>\u65e9\u671f\u9519\u8bef\u68c0\u6d4b<\/li>\n<li>\u63d0\u9ad8 <\/li>\n<li>\u589e\u5f3a\u4ee3\u7801\u53ef\u9760\u6027<\/li>\n<li>\u66f4\u597d\u7684\u4ee3\u7801\u5b8c\u6210\u548c intellisense<\/li>\n<li>\u5927\u578b\u9879\u76ee\u652f\u6301<\/li>\n<\/ul>\n<h3> \u539f\u59cb\u548c\u975e\u539f\u59cb\u6570\u636e\u7c7b\u578b <\/h3>\n<p>\u539f\u59cb\u6570\u636e\u7c7b\u578b\u8868\u793a\u5355\u4e2a\u503c\u5e76\u76f4\u63a5\u5b58\u50a8\u5728\u5185\u5b58\u4e2d\u3002\u4ee5\u4e0b\u662f typescript \u4e2d\u4f7f\u7528\u7684\u4e00\u4e9b\u539f\u59cb\u6570\u636e\u7c7b\u578b<\/p>\n<ul>\n<li>\u5b57\u7b26\u4e32<\/li>\n<li>\u6570\u5b57<\/li>\n<li>\u5e03\u5c14\u503c<\/li>\n<li>\u672a\u5b9a\u4e49<\/li>\n<li>\u7a7a <\/li>\n<\/ul>\n<pre>let name : string = \"kishor\";\nlet age : number = 27;\nlet isdeveloper: boolen = true;\nlet x : null = null;\nlet y: undefined = undefined;\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><em>\u6b63\u5982\u60a8\u5728\u793a\u4f8b\u4e2d\u770b\u5230\u7684\uff0c\u8981\u4e3a\u53d8\u91cf\u5206\u914d\u7c7b\u578b\uff0c\u60a8\u5fc5\u987b\u5728\u5b9a\u4e49\u53d8\u91cf\u540d\u79f0\u548c\u7c7b\u578b\u540e\u4f7f\u7528\u5192\u53f7 (&nbsp;\ud83d\ude42 \u7b26\u53f7\u3002<\/em><\/p>\n<p>\u975e\u539f\u59cb\u6570\u636e\u7c7b\u578b\uff0c\u4e5f\u79f0\u4e3a\u5f15\u7528\u7c7b\u578b\uff0c\u8868\u793a\u590d\u6742\u7684\u6570\u636e\u7ed3\u6784\uff0c\u5e76\u5b58\u50a8\u4e3a\u5bf9\u5185\u5b58\u4f4d\u7f6e\u7684\u5f15\u7528\u3002 typescript \u652f\u6301\u4ee5\u4e0b\u975e\u539f\u59cb\u6570\u636e\u7c7b\u578b\uff1a<\/p>\n<ul>\n<li>\u5bf9\u8c61<\/li>\n<li>\u6570\u7ec4<\/li>\n<li>\u5143\u7ec4<\/li>\n<li>\u529f\u80fd <\/li>\n<\/ul>\n<pre>let person: {name: string, age : number} = {name: \"kishor\", age: 27}; \/\/object\nlet numbers: number[] = [1,2,3,4];\nlet fruits: string[]= [\"apple\", \"pineapple\", \"banana\"];\nlet tuple: [string, number, boolean] = [\"xyz\", 123, true];\nfunction greet(name: string) : any {\n  return `hello ${name}`\n}\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h3> \u7c7b\u578b\u522b\u540d <\/h3>\n<p>typescript \u4e2d\u7684\u7c7b\u578b\u522b\u540d\u662f\u4e00\u79cd\u4e3a\u200b\u200b\u73b0\u6709\u7c7b\u578b\u8d4b\u4e88\u65b0\u540d\u79f0\u7684\u65b9\u6cd5\u3002\u8fd9\u53ef\u4ee5\u4f7f\u60a8\u7684\u4ee3\u7801\u66f4\u5177\u53ef\u8bfb\u6027\u548c\u53ef\u7ef4\u62a4\u6027\uff0c\u5c24\u5176\u662f\u5728\u5904\u7406\u590d\u6742\u7c7b\u578b\u65f6\u3002<\/p>\n<pre>\/\/ defining a type alias for a person object\ntype person = {\n  name: string;\n  age: number;\n};\n\/\/ using the type alias\nconst person1: person = {\n  name: \"alice\",\n  age: 30\n};\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u6b64\u793a\u4f8b\u4e2d\uff0cperson \u662f\u4e00\u4e2a\u7c7b\u578b\u522b\u540d\uff0c\u8868\u793a\u5177\u6709\u540d\u79f0\u548c\u5e74\u9f84\u5c5e\u6027\u7684\u5bf9\u8c61\u3002<br \/> typescript \u4e2d\u7684\u5e76\u96c6\u548c\u4ea4\u96c6\u7c7b\u578b<br \/> \u8054\u5408\u7c7b\u578b\u8868\u793a\u53ef\u4ee5\u662f\u591a\u79cd\u7c7b\u578b\u4e4b\u4e00\u7684\u503c\u3002\u5b83\u662f\u4f7f\u7528 | \u5b9a\u4e49\u7684\u8fd0\u7b97\u7b26\u3002<br \/> \u4ea4\u53c9\u7c7b\u578b\u5c06\u591a\u79cd\u7c7b\u578b\u5408\u5e76\u4e3a\u4e00\u79cd\u7c7b\u578b\u3002\u5b83\u662f\u4f7f\u7528 &amp; \u8fd0\u7b97\u7b26\u5b9a\u4e49\u7684\u3002<\/p>\n<pre>type stringornumber = string | number; \/\/union type\nlet value: stringornumber = \"hello\";\nvalue = 42;\ntype person = {\n    name: string;\n    age: number;\n};\ntype address = {\n    street: string;\n    city: string;\n};\ntype personwithaddress = person &amp; address;\/\/intersection type\nconst personwithaddress: personwithaddress = {\n    name: \"alice\",\n    age: 30,\n    street: \"123 main st\",\n    city: \"anytown\"\n};\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h3> \u4ece\u672a\u3001\u672a\u77e5 <\/h3>\n<p>never \u7c7b\u578b\u8868\u793a\u4ece\u672a\u51fa\u73b0\u8fc7\u7684\u503c\u3002<br \/> \u672a\u77e5\u7c7b\u578b\u4ee3\u8868\u4efb\u4f55\u503c\u3002\u5b83\u6bd4 any \u7c7b\u578b\u66f4\u5b89\u5168\uff0c\u56e0\u4e3a\u5728\u4f7f\u7528\u672a\u77e5\u7c7b\u578b\u7684\u503c\u4e4b\u524d\u5fc5\u987b\u6267\u884c\u7c7b\u578b\u68c0\u67e5\u6216\u65ad\u8a00\u3002<\/p>\n<pre>function error(message: string): never {\n    throw new error(message);\n} \/\/the return type is never because there is no data returned.\nlet value: unknown = \"hello\";\nif (typeof value === \"string\") {\n  let strlength: number = value.length;\n}\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h3> \u7c7b\u578b\u65ad\u8a00 <\/h3>\n<p>\u7c7b\u578b\u65ad\u8a00\u662f\u4e00\u79cd\u544a\u8bc9 typescript \u7f16\u8bd1\u5668\u60a8\u6bd4\u5b83\u66f4\u4e86\u89e3\u7c7b\u578b\u7684\u65b9\u6cd5\u3002\u8fd9\u662f\u4e00\u79cd\u663e\u5f0f\u6307\u5b9a\u53d8\u91cf\u7c7b\u578b\u7684\u65b9\u6cd5<\/p>\n<pre>let value: unknown = \"hello\";\nlet strlength: number = (value as string).length;\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h3> \u7c7b\u578b\u4fdd\u62a4\u88c5\u7f6e <\/h3>\n<p>\u7c7b\u578b\u4fdd\u62a4\u5141\u8bb8\u60a8\u6839\u636e\u67d0\u4e9b\u6761\u4ef6\u7f29\u5c0f\u53d8\u91cf\u7684\u7c7b\u578b\u8303\u56f4\u3002\u901a\u8fc7\u5728\u8bbf\u95ee\u53d8\u91cf\u7684\u5c5e\u6027\u6216\u65b9\u6cd5\u4e4b\u524d\u68c0\u67e5\u53d8\u91cf\u7684\u7c7b\u578b\uff0c\u60a8\u53ef\u4ee5\u907f\u514d\u6f5c\u5728\u7684\u8fd0\u884c\u65f6\u9519\u8bef\u3002<\/p>\n<ul>\n<li> \u8fd0\u7b97\u7b26\u7c7b\u578b<\/li>\n<li> \u5b9e\u4f8b\u64cd\u4f5c\u7b26 <\/li>\n<\/ul>\n<pre>\/\/typeof\nfunction printvalue(value: unknown) {\n    if (typeof value === \"string\") {\n        console.log(value.touppercase());\n    } else if (typeof value === \"number\") {\n        console.log(value.tofixed(2));   \n    }\n}\n\/\/instanceof\nfunction printdate(date: unknown) {\n    if (date instanceof date) {\n        console.log(date.toisostring());\n    }\n}\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h3> typescript \u4e2d\u7684\u63a5\u53e3 <\/h3>\n<p>typescript \u4e2d\u7684\u63a5\u53e3\u662f\u7528\u4e8e\u521b\u5efa\u5177\u6709\u7279\u5b9a\u5c5e\u6027\u7684\u5bf9\u8c61\u7684\u84dd\u56fe\u3002<\/p>\n<pre>interface person {\n  firstname: string;\n  lastname: string;\n  age: number;\n}\nconst person1: person = {\n  firstname: \"alice\",\n  lastname: \"johnson\",\n  age: 30\n};\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u6b64\u793a\u4f8b\u4e2d\uff0cperson \u63a5\u53e3\u5b9a\u4e49\u4e86 person \u5bf9\u8c61\u5fc5\u987b\u5177\u6709firstname\u3001lastname \u548cage \u5c5e\u6027\u3002\u521b\u5efa person1 \u5bf9\u8c61\u65f6<\/p>\n<h3> typescript \u4e2d\u7684\u6cdb\u578b <\/h3>\n<p>\u6cdb\u578b\u662f typescript \u4e2d\u7684\u4e00\u9879\u5f3a\u5927\u529f\u80fd\uff0c\u5b83\u5141\u8bb8\u60a8\u521b\u5efa\u53ef\u4ee5\u5904\u7406\u4e0d\u540c\u6570\u636e\u7c7b\u578b\u7684\u53ef\u91cd\u7528\u7ec4\u4ef6\u3002<\/p>\n<pre>function identity&lt;t&gt;(arg: t): t {\n  return arg;\n}\nidentity&lt;string&gt;(string);\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u6b64\u793a\u4f8b\u4e2d\uff0ct \u662f\u7c7b\u578b\u53c2\u6570\u3002\u5b83\u4ee3\u8868\u4efb\u4f55\u7c7b\u578b\u7684\u5360\u4f4d\u7b26\u3002\u5f53\u4f60\u8c03\u7528\u6052\u7b49\u51fd\u6570\u65f6\uff0c\u4f60\u53ef\u4ee5\u4f20\u9012\u4efb\u4f55\u7c7b\u578b\u7684\u53c2\u6570\uff0c\u51fd\u6570\u5c06\u8fd4\u56de\u76f8\u540c\u7684\u7c7b\u578b\u3002<\/p>\n<h3> typescript \u4e2d\u7684\u7ea6\u675f <\/h3>\n<p>\u5728 typescript \u4e2d\uff0c\u6cdb\u578b\u7ea6\u675f\u5141\u8bb8\u60a8\u5bf9\u53ef\u4ee5\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9\u6cdb\u578b\u51fd\u6570\u6216\u7528\u4f5c\u6cdb\u578b\u7c7b\u6216\u63a5\u53e3\u4e2d\u7684\u7c7b\u578b\u53c2\u6570\u7684\u7c7b\u578b\u5e94\u7528\u9650\u5236\u3002<\/p>\n<pre>interface person {\n    name: string;\n    age: number;\n}\nfunction identity&lt;t extends person&gt;(arg: t): t {\n  return arg;\n}\nconst result  = identity&lt;person&gt;({\n    name: \"aa\";\n    age: 12;\n});\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u91cc\u4f7f\u7528extends\u5173\u952e\u5b57\u6765\u7ea6\u675f\u6570\u636e<\/p>\n<h3> \u64cd\u4f5c\u5458\u7684\u94a5\u5319 <\/h3>\n<p>typescript \u4e2d\u7684 keyof \u8fd0\u7b97\u7b26\u7528\u4e8e\u83b7\u53d6\u5bf9\u8c61\u7c7b\u578b\u7684\u6240\u6709\u5c5e\u6027\u540d\u79f0\u7684\u8054\u5408\u7c7b\u578b\u3002\u8fd9\u5728\u4f7f\u7528\u6cdb\u578b\u7c7b\u578b\u548c\u6620\u5c04\u7c7b\u578b\u65f6\u7279\u522b\u6709\u7528\u3002<\/p>\n<pre>interface person {\n  name: string;\n  age: number;\n}\ntype personkeys = keyof person; \/\/ type: \"name\" | \"age\"\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h3> \u5b9e\u7528\u7a0b\u5e8f\u7c7b\u578b <\/h3>\n<p>pick \uff1a\u4ece t \u4e2d\u9009\u62e9\u7279\u5b9a\u5c5e\u6027  <\/p>\n<pre>type person = {\n  name: string;\n  age: number;\n  email: string;\n}\n\/\/pick&lt;t,k&gt;\ntype name = pick&lt;person, \"name\"&gt;;\ntype nameage = pick&lt;person, \"name\" | \"age\"&gt;\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>omit \uff1a\u7701\u7565 t \u4e2d\u7684\u7279\u5b9a\u5c5e\u6027  <\/p>\n<pre>type person = {\n  name: string;\n  age: number;\n  email: string;\n}\n\/\/omit&lt;t,k&gt;\ntype email= omit&lt;person, \"name\" | \"age\"&gt;;\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>partial \uff1a\u4f7f t \u7684\u6240\u6709\u5c5e\u6027\u53ef\u9009\u3002  <\/p>\n<pre>interface person {\n    name: string;\n    age: number;\n}\ntype partialperson = partial&lt;person&gt;; \/\/ { name?: string; age?: number; }\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4ed6\u4eba\u559c\u6b22\uff0c<br \/> \u5fc5\u586b <br \/> \u53ea\u8bfb <br \/> \u8bb0\u5f55 <\/p>\n<h3> typescript \u4e2d\u7684\u7c7b <\/h3>\n<p>\u5728 typescript \u4e2d\uff0c\u7c7b\u662f\u4f7f\u7528 class \u5173\u952e\u5b57\u5b9a\u4e49\u7684\u3002<\/p>\n<pre>class person {\n    firstname: string;\n    lastname: string;\n\n    constructor(firstname: string, lastname: string) {\n        this.firstname = firstname;\n        this.lastname = lastname;   \n\n    }\n\n    greet() {\n        console.log(\"hello, my name is \" + this.firstname + \" \" + this.lastname);   \n\n    }\n}\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h3> typescript \u4e2d\u7684\u8bbf\u95ee\u4fee\u9970\u7b26 <\/h3>\n<p>public \u7c7b\u6210\u5458\u7684\u9ed8\u8ba4\u53ef\u89c1\u6027\u662fpublic\u3002\u516c\u5171\u6210\u5458\u53ef\u4ee5\u5728\u4efb\u4f55\u5730\u65b9\u8bbf\u95ee<br \/> \u53d7\u4fdd\u62a4\u7684\u6210\u5458\u4ec5\u5bf9\u58f0\u660e\u5b83\u4eec\u7684\u7c7b\u7684\u5b50\u7c7b\u53ef\u89c1\u3002<br \/> \u79c1\u4eba\u6210\u5458\u53ea\u80fd\u5728\u73ed\u7ea7\u5185\u8bbf\u95ee\u3002<\/p>\n<h3> typescript \u4e2d\u7684\u9759\u6001\u6210\u5458 <\/h3>\n<p>typescript \u4e2d\u7684\u9759\u6001\u6210\u5458\u662f\u5c5e\u4e8e\u7c7b\u672c\u8eab\u7684\u6210\u5458\uff08\u5c5e\u6027\u548c\u65b9\u6cd5\uff09\uff0c\u800c\u4e0d\u662f\u5c5e\u4e8e\u7c7b\u7684\u5404\u4e2a\u5b9e\u4f8b\u3002<\/p>\n<pre>class myclass {\n    static staticproperty: string = \"static property\";\n\n    static staticmethod() {\n        console.log(\"static method\");\n    }\n}\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h3> \u5728 typescript \u4e2d\u5b9e\u73b0 <\/h3>\n<p>\u5728 typescript \u4e2d\uff0c\u63a5\u53e3\u5b9a\u4e49\u4e86\u8981\u5b9e\u73b0\u7684\u7c7b\u7684\u5951\u7ea6\u3002\u5b9e\u73b0\u63a5\u53e3\u7684\u7c7b\u5fc5\u987b\u5177\u6709\u63a5\u53e3\u4e2d\u58f0\u660e\u7684\u6240\u6709\u5c5e\u6027\u548c\u65b9\u6cd5\u3002\u4f7f\u7528\u4e86implements\u5173\u952e\u5b57<\/p>\n<pre>interface Shape {\n    area(): number;\n}\n\nclass Circle implements Shape {\n    radius: number;\n\n    constructor(radius: number) {\n        this.radius = radius;\n    }\n\n    area():   \n number {\n        return Math.PI * this.radius * this.radius;   \n\n    }\n}\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h3> \u7ed3\u8bba\uff1a <\/h3>\n<p>\u8fd9\u4e9b\u662f\u6211\u672c\u5468\u5b66\u5230\u7684 typescript \u7684\u4e00\u4e9b\u57fa\u672c\u7528\u4f8b\u3002\u6211\u5b66\u5230\u4e86\u5f88\u591a\u5f88\u9177\u7684\u4e1c\u897f\uff0c\u4f46\u8fd8\u6709\u5f88\u591a\u4e1c\u897f\u6709\u5f85\u53d1\u73b0\u3002 typescript \u4e0d\u65ad\u53d1\u5c55\uff0c\u56e0\u6b64\u6211\u52aa\u529b\u8ddf\u4e0a\u6700\u65b0\u7248\u672c\u548c\u529f\u80fd\uff0c\u5e76\u5173\u6ce8 typescript \u7684\u5b98\u65b9\u6587\u6863\u548c\u535a\u5ba2\u4ee5\u83b7\u53d6\u6700\u65b0\u6d88\u606f\u548c\u6700\u4f73\u5b9e\u8df5\u3002&nbsp;<br \/> \u611f\u8c22\u60a8\u5728\u6211\u7684\u65c5\u9014\u4e2d\u966a\u4f34\u6211\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5b66\u4e60 Typescript \u7684\u65c5\u7a0b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5927\u5bb6\u597d\uff0c\u6211\u6700\u8fd1\u5f00\u59cb\u4e86\u6211\u7684 \u4e4b\u65c5\uff0c\u5e76\u901a\u8fc7\u7f16\u7a0b\u82f1\u96c4\u7684\u9ad8\u7ea7 web \u5f00\u53d1\u8bfe\u7a0b\u53d6\u5f97\u4e86\u8fdb\u6b65\u3002\u6211\u5bf9 typescript \u6709\u4e00\u4e9b\u57fa\u7840\u77e5\u8bc6\uff0c\u4f46\u6ca1\u6709\u6df1\u5165\u63a2\u7d22\u3002\u6211\u7684\u8bfe\u7a0b\u4ece\u6df1\u5165\u7814\u7a76 typescript \u5f00\u59cb\u3002\u4e00\u5468\u8fc7\u53bb\u4e86\uff0c\u6211\u7684\u5b66\u4e60\u6709\u4e86\u5f88\u5927\u7684\u8fdb\u6b65\u3002\u4ee5\u4e0b\u662f\u6211\u6240\u638c\u63e1\u7684\u5173\u952e\u6982\u5ff5\u7684\u7b80\u5316\u6982\u8ff0\u3002 typescript \u5c31\u50cf javascript\uff0c\u4f46\u5177\u6709\u8d85\u80fd\u529b\uff01 typescript \u662f javascript \u7684\u8d85\u96c6\uff0c\u4e3a\u8be5\u8bed\u8a00\u6dfb\u52a0\u4e86\u53ef\u9009\u7684\u9759\u6001\u7c7b\u578b\u3002\u8fd9\u610f\u5473\u7740\u60a8\u53ef\u4ee5\u58f0\u660e\u53d8\u91cf\u3001\u51fd\u6570\u53c2\u6570\u548c\u8fd4\u56de\u503c\u7684\u7c7b\u578b\uff0c\u8fd9\u6709\u52a9\u4e8e\u5728\u5f00\u53d1\u8fc7\u7a0b\u7684\u65e9\u671f\u53d1\u73b0\u6f5c\u5728\u7684\u9519\u8bef\u3002\u4f7f\u7528 typescript \u7684\u597d\u5904 \u65e9\u671f\u9519\u8bef\u68c0\u6d4b \u63d0\u9ad8 \u589e\u5f3a\u4ee3\u7801\u53ef\u9760\u6027 \u66f4\u597d\u7684\u4ee3\u7801\u5b8c\u6210\u548c intellisense \u5927\u578b\u9879\u76ee\u652f\u6301 \u539f\u59cb\u548c\u975e\u539f\u59cb\u6570\u636e\u7c7b\u578b \u539f\u59cb\u6570\u636e\u7c7b\u578b\u8868\u793a\u5355\u4e2a\u503c\u5e76\u76f4\u63a5\u5b58\u50a8\u5728\u5185\u5b58\u4e2d\u3002\u4ee5\u4e0b\u662f typescript \u4e2d\u4f7f\u7528\u7684\u4e00\u4e9b\u539f\u59cb\u6570\u636e\u7c7b\u578b \u5b57\u7b26\u4e32 \u6570\u5b57 \u5e03\u5c14\u503c \u672a\u5b9a\u4e49 \u7a7a let name : string = &#8220;kishor&#8221;; let age : number = 27; let isdeveloper: boolen = true; let x : null = null; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-3466","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3466","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=3466"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3466\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3466"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3466"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3466"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}