<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel>
        <title>AnYaoqi博客</title>
        <link>https://www.anyaoqi.cn/</link>
        <description>一名97年的前端小学生</description>
        <lastBuildDate>Sun, 20 Apr 2025 10:20:12 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <language>en-US</language>
        <copyright>All rights reserved 2025, AnYaoqi</copyright>
        <item>
            <title><![CDATA[前端对接电子秤、扫码枪设备serialPort 串口使用教]]></title>
            <link>https://www.anyaoqi.cn/article/1db6402e-a6a5-800a-974b-f6a496d9039e</link>
            <guid>https://www.anyaoqi.cn/article/1db6402e-a6a5-800a-974b-f6a496d9039e</guid>
            <pubDate>Sun, 20 Apr 2025 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-1db6402ea6a5800a974bf6a496d9039e"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><div class="notion-text notion-block-1db6402ea6a580da9421d0c82e550f81">因为最近工作项目中用到了电子秤，需要对接电子秤设备。以前也没有对接过这种设备，当时也是一脸懵逼，脑袋空空。后来就去网上搜了一下前端怎么对接，然后就发现了<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://serialport.io/">SerialPort</a>串口。</div><blockquote class="notion-quote notion-block-1db6402ea6a5808e90e7f97953842cbf"><div>Serialport</div><div class="notion-text notion-block-1db6402ea6a58093b62cc472dc0d12b8">官网地址：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://serialport.io/">https://serialport.io/</a></div><div class="notion-text notion-block-1db6402ea6a5804c8c4dd67d13cab756">Github：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://github.com/serialport/node-serialport">https://github.com/serialport/node-serialport</a></div><div class="notion-text notion-block-1db6402ea6a580aa82a8fd777413adef">官方描述：使用 JavaScript 访问串行端口。Linux、OSX 和 Windows。</div></blockquote><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-1db6402ea6a580ffaa77cf4a8fb0154d" data-id="1db6402ea6a580ffaa77cf4a8fb0154d"><span><div id="1db6402ea6a580ffaa77cf4a8fb0154d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1db6402ea6a580ffaa77cf4a8fb0154d" title="SerialPort是什么？"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">SerialPort是什么？</span></span></h3><blockquote class="notion-quote notion-block-1db6402ea6a5800c9e79e1e27188e9b2"><div>SerialPort 是一个用于在 Node.js 环境中进行串口通信的库。它允许开发者通过 JavaScript 或 TypeScript 代码与计算机上的串口设备进行交互。SerialPort 库提供了丰富的 API，使得在串口通信中能够方便地进行设置、监听和发送数据。</div></blockquote><div class="notion-text notion-block-1db6402ea6a58093ad7bc3b85b5d4b51">一般我们的设备(电子秤/扫码枪)会有一根线插入到电脑的USB口或者其他口，电脑上的这些插口就是叫<b>串口</b>。设备上的数据会通过这根线传输到电脑里面，比如电子秤传到电脑里的就是重量数值。那么我们前端怎么接收解析到这些数据的呢？<b>SerialPort</b>的作用就是用来帮我们接收设备传输过来的数据，也可以向设备发送数据。</div><div class="notion-text notion-block-1db6402ea6a580b394bef387e4bb5a74">简单概括一下：<b>SerialPort就是我们前端和设备之间的翻译官，可以接收设备传输过来的数据，也可以向设备发送数据。</b></div><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-1db6402ea6a5803eb5a1cda8a67926fb" data-id="1db6402ea6a5803eb5a1cda8a67926fb"><span><div id="1db6402ea6a5803eb5a1cda8a67926fb" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1db6402ea6a5803eb5a1cda8a67926fb" title="SerialPort怎么用？"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">SerialPort怎么用？</span></span></h3><div class="notion-text notion-block-1db6402ea6a5803eba47c6233ebd5a5b">SerialPort可以在Node项目中使用，也可以在Electron项目中使用，我们一般都是用在Electron项目中，接下来讲一下在Electron项目中SerialPort怎么下载和引入</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-1db6402ea6a580dba9daca3e0a533ba0" data-id="1db6402ea6a580dba9daca3e0a533ba0"><span><div id="1db6402ea6a580dba9daca3e0a533ba0" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1db6402ea6a580dba9daca3e0a533ba0" title="1、创建Electron项目"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">1、创建Electron项目</span></span></h4><div class="notion-text notion-block-1db6402ea6a580a5841aec75b94a76ed"><em>网上有很多Electron教程，这里不再详细说了</em></div><div class="notion-text notion-block-1db6402ea6a580589d35c2d3a8180e5d"><b>在package.json中看一下自己的Electron的版本，下一步会用到</b>。</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-1db6402ea6a580b9b583d02b769c590c" data-id="1db6402ea6a580b9b583d02b769c590c"><span><div id="1db6402ea6a580b9b583d02b769c590c" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1db6402ea6a580b9b583d02b769c590c" title="2、下载SerialPort"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2、下载SerialPort</span></span></h4><div class="notion-text notion-block-1db6402ea6a58000bbf9eac39c05e480">这里先看一下自己使用的Electron对应的Node版本是什么，打开下面electron官网看表格中的Node那一列</div><div class="notion-text notion-block-1db6402ea6a580959a5cfdb0da49d1d2">Electron发行时间表：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://www.electronjs.org/zh/docs/latest/tutorial/electron-timelines">https://www.electronjs.org/zh/docs/latest/tutorial/electron-timelines</a></div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-1db6402ea6a58049a669d957b554d9bb"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img src="https://p9-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/9328bc0f648643ec99c126dcb06fd7bf~tplv-k3u1fbpfcp-jj-mark:0:0:0:0:q75.image#?w=922&amp;h=790&amp;s=62283&amp;e=png&amp;b=fbfbfb&amp;t=1db6402e-a6a5-8049-a669-d957b554d9bb" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-1db6402ea6a58003bcfccd6c842f2214">如果你Electron对应的Node版本高于v12.0.0，直接下载就行</div><div class="notion-text notion-block-1db6402ea6a5802d8f05f12bbf58bfc2">如果你Electron对应的Node版本低于或等于v12.0.0，请用对应的Node版本对应下面的serialport版本下载</div><blockquote class="notion-quote notion-block-1db6402ea6a5809badcafc3c04f939c2"><div>https://serialport.io/docs/next/guide-platform-support#last-known-versions-for-unsupported-versions-of-nodejs</div></blockquote><ul class="notion-list notion-list-disc notion-block-1db6402ea6a580ce8612ca2e3a17bb0a"><li>对于 Node.js 版本<code class="notion-inline-code">0.10</code>和<code class="notion-inline-code">0.12</code>，最后一个正常运行的版本是<code class="notion-inline-code">serialport@4</code>。</li></ul><ul class="notion-list notion-list-disc notion-block-1db6402ea6a5805b8247ec0478cd9967"><li>对于 Node.js 版本<code class="notion-inline-code">4.0</code>，最后一个正常运行的版本是<code class="notion-inline-code">serialport@6</code>.</li></ul><ul class="notion-list notion-list-disc notion-block-1db6402ea6a580a78a08d095a1ddb897"><li>对于 Node.js 版本<code class="notion-inline-code">8.0</code>，最后一个正常运行的版本是<code class="notion-inline-code">serialport@8</code>.</li></ul><ul class="notion-list notion-list-disc notion-block-1db6402ea6a58086942ce6c51369c68d"><li>对于 Node.js 版本<code class="notion-inline-code">10.0</code>，最后一个正常运行的版本是<code class="notion-inline-code">serialport@9</code>.</li></ul><ul class="notion-list notion-list-disc notion-block-1db6402ea6a580df9fb9fb011363478a"><li>对于 Node.js 版本<code class="notion-inline-code">12.0</code>，最后一个正常运行的版本是<code class="notion-inline-code">serialport@10</code>.</li></ul><blockquote class="notion-quote notion-block-1db6402ea6a580f1ad56df0c06cb6141"><div>我项目的Electron版本是11.5.0，对应的Node版本号是12.0，对应的serialport版本号是serialport@10.0.0</div></blockquote><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-1db6402ea6a580e0be2ac53f31629f1d" data-id="1db6402ea6a580e0be2ac53f31629f1d"><span><div id="1db6402ea6a580e0be2ac53f31629f1d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1db6402ea6a580e0be2ac53f31629f1d" title="3、编译Serialport"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">3、编译Serialport</span></span></h4><ul class="notion-list notion-list-disc notion-block-1db6402ea6a580b5913ac33b996f00d4"><li>安装node-gyp 用于调用其他语言编写的程序（如果已安装过请忽略这一步）</li><ul class="notion-list notion-list-disc notion-block-1db6402ea6a580b5913ac33b996f00d4"></ul></ul><div class="notion-text notion-block-1db6402ea6a580168b14c899427ec3e9">&lt;!----&gt;</div><ul class="notion-list notion-list-disc notion-block-1db6402ea6a580938c7df38dc659c93b"><li>进入@serialport目录</li><ul class="notion-list notion-list-disc notion-block-1db6402ea6a580938c7df38dc659c93b"></ul></ul><ul class="notion-list notion-list-disc notion-block-1db6402ea6a580829d41c903a955a22d"><li>进行编译，target后面换成当前Electron的版本号</li><ul class="notion-list notion-list-disc notion-block-1db6402ea6a580829d41c903a955a22d"></ul></ul><div class="notion-text notion-block-1db6402ea6a580c8aa5ffc832e882f89">如果编译的时候报错了就将自己电脑的Node版本切换成当前Electron对应的版本号再编译一次</div><div class="notion-text notion-block-1db6402ea6a580aebc85e10ef9db55c9">查看Electron对应Node版本号：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://www.electronjs.org/zh/docs/latest/tutorial/electron-timelines">https://www.electronjs.org/zh/docs/latest/tutorial/electron-timelines</a></div><div class="notion-text notion-block-1db6402ea6a580369adff9eaab9ee5c5">编译成功以后就可以在代码里使用Serialport了</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-1db6402ea6a58091885aff339a1daa1a" data-id="1db6402ea6a58091885aff339a1daa1a"><span><div id="1db6402ea6a58091885aff339a1daa1a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1db6402ea6a58091885aff339a1daa1a" title="4、使用Serialport"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">4、使用Serialport</span></span></h4><blockquote class="notion-quote notion-block-1db6402ea6a580078279c6f27ecdb25b"><div>serialport官网使用教程：https://serialport.io/docs/next/guide-usage</div></blockquote><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-1db6402ea6a5800594c3ff4ec57df3fe" data-id="1db6402ea6a5800594c3ff4ec57df3fe"><span><div id="1db6402ea6a5800594c3ff4ec57df3fe" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1db6402ea6a5800594c3ff4ec57df3fe" title="4.1、引入Serialport"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">4.1、引入Serialport</span></span></h4><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-1db6402ea6a58012bb92cbc71e7267e4" data-id="1db6402ea6a58012bb92cbc71e7267e4"><span><div id="1db6402ea6a58012bb92cbc71e7267e4" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1db6402ea6a58012bb92cbc71e7267e4" title="4.2、创建串口（重点！）"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">4.2、创建串口（重点！）</span></span></h4><div class="notion-text notion-block-1db6402ea6a5809bb92ef676b285072b">创建串口有两种写法，新版本是这样写法<code class="notion-inline-code">new SerialPort(params, callback)</code></div><div class="notion-text notion-block-1db6402ea6a580d5b367f65a0461a6d5">旧版本是下面这样的写法<code class="notion-inline-code">new Serialport(path, params, callback)</code>，我用的是serialport@10.0.0版本就是这样的写法</div><div class="notion-text notion-block-1db6402ea6a580078e03c5e8c0ffa281">创建串口的时候需要传入两个重要的参数是path和baudRate，<b>path是串口号，baudRate是波特率</b>。最后一个参数是回调函数</div><blockquote class="notion-quote notion-block-1db6402ea6a58063b8f2ffc33c320d41"><div>不知道怎么查看串口号和波特率看这篇文章</div><div class="notion-text notion-block-1db6402ea6a58046a1c1e56d9eccc935"><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://juejin.cn/spost/7323264134221774884">如何查看串口号和波特率？</a></div></blockquote><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-1db6402ea6a58001817fec33d2e12418" data-id="1db6402ea6a58001817fec33d2e12418"><span><div id="1db6402ea6a58001817fec33d2e12418" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1db6402ea6a58001817fec33d2e12418" title="4.3、手动打开串口"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">4.3、手动打开串口</span></span></h4><div class="notion-text notion-block-1db6402ea6a580f4ba94fc5eacf44589">如果autoOpen参数是false，需要使用<code class="notion-inline-code">port.open()</code>方法手动打开</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-1db6402ea6a580c3bceafa122a02f400" data-id="1db6402ea6a580c3bceafa122a02f400"><span><div id="1db6402ea6a580c3bceafa122a02f400" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1db6402ea6a580c3bceafa122a02f400" title="4.4、接收数据（重点！）"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">4.4、接收数据（重点！）</span></span></h4><div class="notion-text notion-block-1db6402ea6a58094889dd13f0e0c38a1">接收到的data是一个Buffer，需要转换为字符串进行查看</div><div class="notion-text notion-block-1db6402ea6a580b18e9ddf4e281388bf">接收过来的data就是设备传输过来的数据，转换后的字符串就是我们需要的数据，字符串里面可能有多个数据，我们把自己需要的数据截取出来就可以了</div><div class="notion-text notion-block-1db6402ea6a580839a05ee5835e20567">假设通过电子秤设备获取到的数据就是&quot;205 000 000&quot;，中间是四个空格分割的，第一个数字205就是获取的重量，需要把这个重量截取出来。下面是我的示例代码</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-1db6402ea6a5805ba824e123b2da26dd"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img src="https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/ecdda3dc18fe4a44bad9350b78dedd7e~tplv-k3u1fbpfcp-jj-mark:0:0:0:0:q75.image#?w=600&amp;h=679&amp;s=54940&amp;e=png&amp;b=fefefe&amp;t=1db6402e-a6a5-805b-a824-e123b2da26dd" alt="notion image" loading="lazy" decoding="async"/></div></figure><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-1db6402ea6a5805fba1cc9aaabaa7776" data-id="1db6402ea6a5805fba1cc9aaabaa7776"><span><div id="1db6402ea6a5805fba1cc9aaabaa7776" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1db6402ea6a5805fba1cc9aaabaa7776" title="4.5、写入数据"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">4.5、写入数据</span></span></h4><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-1db6402ea6a58006bab3f4195a66a875" data-id="1db6402ea6a58006bab3f4195a66a875"><span><div id="1db6402ea6a58006bab3f4195a66a875" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1db6402ea6a58006bab3f4195a66a875" title="4.6、实时获取(监听)所有串口"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">4.6、实时获取(监听)所有串口</span></span></h4><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-1db6402ea6a580728378e34abec330e5" data-id="1db6402ea6a580728378e34abec330e5"><span><div id="1db6402ea6a580728378e34abec330e5" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1db6402ea6a580728378e34abec330e5" title="更多内容"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">更多内容</span></span></h4><div class="notion-text notion-block-1db6402ea6a5806cbac6e6e8d54f3bff">serialport官网教程：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://serialport.io/docs/next/guide-usage">https://serialport.io/docs/next/guide-usage</a></div><div class="notion-blank notion-block-1db6402ea6a580af98c3fb7f4130cd76"> </div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[解决node上传文件乱码问题终极方案]]></title>
            <link>https://www.anyaoqi.cn/article/1db6402e-a6a5-80ac-aa64-e1adc13a8eaa</link>
            <guid>https://www.anyaoqi.cn/article/1db6402e-a6a5-80ac-aa64-e1adc13a8eaa</guid>
            <pubDate>Sun, 20 Apr 2025 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-1db6402ea6a580acaa64e1adc13a8eaa"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-1db6402ea6a580b689a0c34d2544f897" data-id="1db6402ea6a580b689a0c34d2544f897"><span><div id="1db6402ea6a580b689a0c34d2544f897" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1db6402ea6a580b689a0c34d2544f897" title="问题描述"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">问题描述</span></span></h3><div class="notion-text notion-block-1db6402ea6a5803cb704e81df6054742">今天在<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://www.runoob.com/nodejs/nodejs-express-framework.html">菜鸟教程学习node上传文件</a>时遇到了一个中文乱码的问题，文件名包含中文就会显示乱码，上传到服务器的文件名也是乱码。试了两个方法都不行，最后还是问了万能的度娘才解决。</div><div class="notion-blank notion-block-1db6402ea6a580cbbb20c0bdbccbbe2b"> </div><div class="notion-text notion-block-1db6402ea6a58038a6a3ed62d99dfa21">我做了一个非常简单的上传文件的界面，</div><ul class="notion-list notion-list-disc notion-block-1db6402ea6a5809aa272c19fa4f09e6d"><li>第一步选择文件</li></ul><ul class="notion-list notion-list-disc notion-block-1db6402ea6a58037afe8f36704d84d5a"><li>第二步点击上传文件，上传到node后端服务</li></ul><div class="notion-text notion-block-1db6402ea6a580698fc8ca7066a5eb8a"><b>上传文件的界面</b></div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-1db6402ea6a58083a963dfea041da1d3"><div style="position:relative;display:flex;justify-content:center;align-self:start;width:684px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F263af646-cf28-4ae4-ae26-f18009e76d71%2FUntitled.png?table=block&amp;id=1db6402e-a6a5-8083-a963-dfea041da1d3&amp;t=1db6402e-a6a5-8083-a963-dfea041da1d3&amp;width=684&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><ul class="notion-list notion-list-disc notion-block-1db6402ea6a580f9a71ec89ded21c27b"><li>node后端服务会上传文件，上传成功后会把文件名返回前端显示出来，这时候就会显示乱码了</li></ul><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-1db6402ea6a580fa9abee9f1fd027778"><div style="position:relative;display:flex;justify-content:center;align-self:start;width:446px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F5a67b85c-bf22-4ce0-b1b4-75a26336ac5e%2FUntitled.png?table=block&amp;id=1db6402e-a6a5-80fa-9abe-e9f1fd027778&amp;t=1db6402e-a6a5-80fa-9abe-e9f1fd027778&amp;width=446&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-1db6402ea6a58080b3dbe7309049b809"><div style="position:relative;display:flex;justify-content:center;align-self:start;width:675px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F2a20c9da-b135-4bdd-a667-2efbfb4a9321%2FUntitled.png?table=block&amp;id=1db6402e-a6a5-8080-b3db-e7309049b809&amp;t=1db6402e-a6a5-8080-b3db-e7309049b809&amp;width=675&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-1db6402ea6a5807ebd8fde906250e262" data-id="1db6402ea6a5807ebd8fde906250e262"><span><div id="1db6402ea6a5807ebd8fde906250e262" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1db6402ea6a5807ebd8fde906250e262" title="node上传文件代码"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">node上传文件代码</span></span></h3><div class="notion-blank notion-block-1db6402ea6a5804680cecd30e188478a"> </div><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-1db6402ea6a580f3ac28f90eaa684fe0" data-id="1db6402ea6a580f3ac28f90eaa684fe0"><span><div id="1db6402ea6a580f3ac28f90eaa684fe0" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1db6402ea6a580f3ac28f90eaa684fe0" title="解决过程"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">解决过程</span></span></h3><div class="notion-text notion-block-1db6402ea6a580669ce9cf9aa046a8cf">在文章底下别人的笔记里面看到了关于这个问题的两个解决方案，决定尝试一下，尝试过后发现还是会乱码，不知道为什么，总之这两个方案都没有能解决我的问题。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-1db6402ea6a5802ca730ece818a80909"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Fedb94c2e-c19b-499b-8d0f-63f148b7e788%2FUntitled.png?table=block&amp;id=1db6402e-a6a5-802c-a730-ece818a80909&amp;t=1db6402e-a6a5-802c-a730-ece818a80909&amp;width=709.984375&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-blank notion-block-1db6402ea6a580bab684cb733a6f46c1"> </div><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-1db6402ea6a580f7bd1aeafbd92b0b82" data-id="1db6402ea6a580f7bd1aeafbd92b0b82"><span><div id="1db6402ea6a580f7bd1aeafbd92b0b82" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1db6402ea6a580f7bd1aeafbd92b0b82" title="最终解决方案"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">最终解决方案</span></span></h3><div class="notion-text notion-block-1db6402ea6a580458fcccd8d24a4bf23">后来去问了度娘，看到了一个比较靠谱的解决方案，决定尝试一下。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-1db6402ea6a5802e8ab9f01fd8d7f0d8"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Fc1223abf-4305-487c-9956-9c72468653b2%2FUntitled.png?table=block&amp;id=1db6402e-a6a5-802e-8ab9-f01fd8d7f0d8&amp;t=1db6402e-a6a5-802e-8ab9-f01fd8d7f0d8&amp;width=709.984375&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-1db6402ea6a580829faef080f308634f">加上这段代码后上传到服务器的文件没有乱码了，但是页面上显示的还是会乱码。</div><div class="notion-text notion-block-1db6402ea6a580fa93a0fdc65083dd24">然后又加上了方案一的代码，页面上也不乱码了。</div><div class="notion-blank notion-block-1db6402ea6a580308f87c64e08179232"> </div><div class="notion-blank notion-block-1db6402ea6a580a288b1ed1869cfb101"> </div><div class="notion-text notion-block-1db6402ea6a580a19a77d97163f46908"><b>总结：上面这两段代码都加上就可以解决node上传文件时中文乱码的问题</b></div><div class="notion-blank notion-block-1db6402ea6a580339ca8d0b949ce5b41"> </div><div class="notion-text notion-block-1db6402ea6a580c7b617e8ce30e5e6dc">附上我改完后的完整代码</div><div class="notion-blank notion-block-1db6402ea6a580a7a9bfc0b9c463c987"> </div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TypeScript 基础]]></title>
            <link>https://www.anyaoqi.cn/article/1db6402e-a6a5-8071-9d47-fc7b22515291</link>
            <guid>https://www.anyaoqi.cn/article/1db6402e-a6a5-8071-9d47-fc7b22515291</guid>
            <pubDate>Sun, 20 Apr 2025 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-1db6402ea6a580719d47fc7b22515291"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-1db6402ea6a5803fb202f0515cfd66e0" data-id="1db6402ea6a5803fb202f0515cfd66e0"><span><div id="1db6402ea6a5803fb202f0515cfd66e0" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1db6402ea6a5803fb202f0515cfd66e0" title="1. 原始数据类型"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>1. 原始数据类型</b></span></span></h3><ul class="notion-list notion-list-disc notion-block-1db6402ea6a5807c92b8d307cae27a04"><li>Boolean</li></ul><ul class="notion-list notion-list-disc notion-block-1db6402ea6a5809ba85de7d45a0f3e19"><li>number</li></ul><ul class="notion-list notion-list-disc notion-block-1db6402ea6a58012a9daf18df888cc48"><li>string</li></ul><ul class="notion-list notion-list-disc notion-block-1db6402ea6a58091b28ec6a5b3c07e6a"><li>undefined</li></ul><ul class="notion-list notion-list-disc notion-block-1db6402ea6a580fdb214f45a0d590f1e"><li>null</li></ul><ul class="notion-list notion-list-disc notion-block-1db6402ea6a580fc8da6c1c7086222cf"><li>any</li></ul><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-1db6402ea6a580d38b56c0e6aaa0c23c" data-id="1db6402ea6a580d38b56c0e6aaa0c23c"><span><div id="1db6402ea6a580d38b56c0e6aaa0c23c" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1db6402ea6a580d38b56c0e6aaa0c23c" title="2. 数组和元祖"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>2. 数组和元祖</b></span></span></h3><div class="notion-text notion-block-1db6402ea6a5808a82c2e754e8c4d677">元祖：本质上其实就是数组，不过跟数组不一样的就是可以单独限制数组中的每个数据类型</div><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-1db6402ea6a580e38d5fc0549536a420" data-id="1db6402ea6a580e38d5fc0549536a420"><span><div id="1db6402ea6a580e38d5fc0549536a420" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1db6402ea6a580e38d5fc0549536a420" title="3. interface接口"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>3. interface接口</b></span></span></h3><ul class="notion-list notion-list-disc notion-block-1db6402ea6a580e8ad14d9362efe39fb"><li>通过interface关键字定义接口</li></ul><ul class="notion-list notion-list-disc notion-block-1db6402ea6a580069fedda8729cddac2"><li>属性前添加readonly表示只读属性</li></ul><ul class="notion-list notion-list-disc notion-block-1db6402ea6a5807f8fe7f116f52a315f"><li>属性后加?问号表示可选属性</li></ul><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-1db6402ea6a580b3a35dc9a291a64f0d" data-id="1db6402ea6a580b3a35dc9a291a64f0d"><span><div id="1db6402ea6a580b3a35dc9a291a64f0d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1db6402ea6a580b3a35dc9a291a64f0d" title="4. 类型推论、联合类型、类型断言"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>4. 类型推论、联合类型、类型断言</b></span></span></h3><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-1db6402ea6a5808ba04ecbd9f6041085" data-id="1db6402ea6a5808ba04ecbd9f6041085"><span><div id="1db6402ea6a5808ba04ecbd9f6041085" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1db6402ea6a5808ba04ecbd9f6041085" title="类型推论"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>类型推论</b></span></span></h4><blockquote class="notion-quote notion-block-1db6402ea6a5806baedffc9ec6dad262"><div>变量不需要声明类型，根据赋值自定推论出变量类型</div></blockquote><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-1db6402ea6a5806b83c1e8357d9bb74a" data-id="1db6402ea6a5806b83c1e8357d9bb74a"><span><div id="1db6402ea6a5806b83c1e8357d9bb74a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1db6402ea6a5806b83c1e8357d9bb74a" title="联合类型"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>联合类型</b></span></span></h4><blockquote class="notion-quote notion-block-1db6402ea6a580909d7ef61528bb7c1a"><div>联合类型就是可以指定多个类型</div></blockquote><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-1db6402ea6a58066bde4e64c6d26f5bb" data-id="1db6402ea6a58066bde4e64c6d26f5bb"><span><div id="1db6402ea6a58066bde4e64c6d26f5bb" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1db6402ea6a58066bde4e64c6d26f5bb" title="类型断言"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>类型断言</b></span></span></h4><blockquote class="notion-quote notion-block-1db6402ea6a58066928bc51aa62d0e45"><div>当变量不确定是什么类型，但是我们知道会是什么类型时，可以断言为某种具体类型</div></blockquote><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-1db6402ea6a580168bcdc5fdd2d71d34" data-id="1db6402ea6a580168bcdc5fdd2d71d34"><span><div id="1db6402ea6a580168bcdc5fdd2d71d34" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1db6402ea6a580168bcdc5fdd2d71d34" title="通过as关键字断言"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>通过as关键字断言</b></span></span></h4><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-1db6402ea6a580b29c0ac9af0698a5de" data-id="1db6402ea6a580b29c0ac9af0698a5de"><span><div id="1db6402ea6a580b29c0ac9af0698a5de" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1db6402ea6a580b29c0ac9af0698a5de" title="隐式断言"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>隐式断言</b></span></span></h4><blockquote class="notion-quote notion-block-1db6402ea6a580db92b0f29fd2bef846"><div>不需要主动断言，ts会根据代码逻辑自动断言出类型</div></blockquote><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-1db6402ea6a5805c8667f4ddcafc2a3e" data-id="1db6402ea6a5805c8667f4ddcafc2a3e"><span><div id="1db6402ea6a5805c8667f4ddcafc2a3e" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1db6402ea6a5805c8667f4ddcafc2a3e" title="5. 枚举enums"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>5. 枚举enums</b></span></span></h3><blockquote class="notion-quote notion-block-1db6402ea6a580f08acbf0aacb3a42da"><div>枚举就是固定的几个值，比如每周的工作日，红绿灯的颜色。</div><div class="notion-text notion-block-1db6402ea6a5807a9fa1cd820aa8e82c">类似数组，默认索引是从0开始的数字，索引可以修改。</div></blockquote><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-1db6402ea6a5809382f9e41088c4ca50" data-id="1db6402ea6a5809382f9e41088c4ca50"><span><div id="1db6402ea6a5809382f9e41088c4ca50" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1db6402ea6a5809382f9e41088c4ca50" title="枚举"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>枚举</b></span></span></h4><div class="notion-text notion-block-1db6402ea6a580fdb1aef050701463a1">编译后的js代码</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-1db6402ea6a580e0b582d303900dbd5e" data-id="1db6402ea6a580e0b582d303900dbd5e"><span><div id="1db6402ea6a580e0b582d303900dbd5e" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1db6402ea6a580e0b582d303900dbd5e" title="常量枚举"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>常量枚举</b></span></span></h4><blockquote class="notion-quote notion-block-1db6402ea6a580829d90f9be227859c5"><div>在enum前面加一个const就可以变为常量枚举</div><div class="notion-text notion-block-1db6402ea6a580f4b325c3c76a23a65b">常量枚举编译后的js代码量少，因为编译成了对应的值，没有枚举创建的过程了。</div></blockquote><div class="notion-text notion-block-1db6402ea6a580d79749c94179b08133">编译后的js代码</div><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-1db6402ea6a58047ad3dd4365d392d3b" data-id="1db6402ea6a58047ad3dd4365d392d3b"><span><div id="1db6402ea6a58047ad3dd4365d392d3b" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1db6402ea6a58047ad3dd4365d392d3b" title="6. 泛型"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>6. 泛型</b></span></span></h3><blockquote class="notion-quote notion-block-1db6402ea6a5809d957fd3495c644f2b"><div>定义函数、接口和类的时候不指定类型，使用的时候再定义类型</div><div class="notion-text notion-block-1db6402ea6a580ea9140c6071e83ca7f">定义的时候先创建泛型名称，使用泛型代替类型，也就是泛型代指某一种具体类型。</div></blockquote><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-1db6402ea6a5808f9719da213b61d08a" data-id="1db6402ea6a5808f9719da213b61d08a"><span><div id="1db6402ea6a5808f9719da213b61d08a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1db6402ea6a5808f9719da213b61d08a" title="泛型-第一部分：定义泛型"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>泛型-第一部分：定义泛型</b></span></span></h4><div class="notion-text notion-block-1db6402ea6a580e4b50dfb630fc6157f">定义函数、接口和类的时候，在名称后面加上<code class="notion-inline-code">&lt; &gt;</code>来定义泛型，<code class="notion-inline-code">&lt; &gt;</code>里面加上泛型的名称</div><ul class="notion-list notion-list-disc notion-block-1db6402ea6a580db9344f73f73a31972"><li>&lt;T&gt; 创建了一个名称为T的泛型，<b>T到底是什么类型不知道，可能是任何一种，具体是什么要看使用时传入的类型。</b></li></ul><ul class="notion-list notion-list-disc notion-block-1db6402ea6a580d39d47d794aff39501"><li>arg: T 使用泛型T作为入参的类型</li></ul><ul class="notion-list notion-list-disc notion-block-1db6402ea6a58079b391caaa91fd7316"><li>将泛型T作为函数返回值</li></ul><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-1db6402ea6a580cca492c70d55f9eecd" data-id="1db6402ea6a580cca492c70d55f9eecd"><span><div id="1db6402ea6a580cca492c70d55f9eecd" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1db6402ea6a580cca492c70d55f9eecd" title="定义多个泛型"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>定义多个泛型</b></span></span></h4><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-1db6402ea6a580429317ee764b919f13" data-id="1db6402ea6a580429317ee764b919f13"><span><div id="1db6402ea6a580429317ee764b919f13" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1db6402ea6a580429317ee764b919f13" title="泛型-第二部分：约束泛型"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>泛型-第二部分：约束泛型</b></span></span></h4><blockquote class="notion-quote notion-block-1db6402ea6a58046baddee5c46e13d7d"><div>通过泛型约束传入的参数中必须包含某个属性，通过添加extends关键字约束泛型。</div></blockquote><div class="notion-text notion-block-1db6402ea6a580ffba33c7897d26c02c">上面的函数中会报一个警告：类型“T”上不存在属性“length”。</div><div class="notion-text notion-block-1db6402ea6a580dc8dafdb383837c8ed">如果泛型T是string或者array没问题，因为本身就有length，但如果是number就会报错，因为number没有length属性。因为ts不知道泛型T会是什么类型，所以也就不知道arg上面会不会有length属性。</div><div class="notion-text notion-block-1db6402ea6a580f789c8deaf713caefd">如果使用<b>泛型约束</b>就可以很好的解决上面得问题，因为可以约束泛型T必须包含length属性。</div><div class="notion-text notion-block-1db6402ea6a5803f8436f01301628d2c"><b>通过</b><code class="notion-inline-code"><b>extends</b></code><b>关键字约束泛型</b></div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-1db6402ea6a5804dbc18f06c9e478ea7" data-id="1db6402ea6a5804dbc18f06c9e478ea7"><span><div id="1db6402ea6a5804dbc18f06c9e478ea7" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1db6402ea6a5804dbc18f06c9e478ea7" title="泛型-第三部分：泛型在类和接口中的使用"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>泛型-第三部分：泛型在类和接口中的使用</b></span></span></h4><div class="notion-text notion-block-1db6402ea6a58059812ceb9d2cb13ddd"><b>在类中的使用</b></div><div class="notion-text notion-block-1db6402ea6a5805ca5a0f8d465f758a1"><b>在接口中的使用</b></div><div class="notion-text notion-block-1db6402ea6a58043b4fef4e150ffcc3d"><b>通过泛型创建数组</b></div><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-1db6402ea6a58081b091f93ca3d706a8" data-id="1db6402ea6a58081b091f93ca3d706a8"><span><div id="1db6402ea6a58081b091f93ca3d706a8" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1db6402ea6a58081b091f93ca3d706a8" title="7. 类型别名、字面量、交叉类型"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>7. 类型别名、字面量、交叉类型</b></span></span></h3><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-1db6402ea6a580848e2acea575353ceb" data-id="1db6402ea6a580848e2acea575353ceb"><span><div id="1db6402ea6a580848e2acea575353ceb" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1db6402ea6a580848e2acea575353ceb" title="类型别名"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>类型别名</b></span></span></h4><blockquote class="notion-quote notion-block-1db6402ea6a5803bb193e14654924300"><div>有些类型名称比较长，就是给类型起一个别的名称</div></blockquote><div class="notion-text notion-block-1db6402ea6a580a88ba5c39c7187fd30">如果多个函数都是这样的类型就需要写很多次，可以给这个类型定义一个别名使用</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-1db6402ea6a580a59b51ead9933e6b66" data-id="1db6402ea6a580a59b51ead9933e6b66"><span><div id="1db6402ea6a580a59b51ead9933e6b66" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1db6402ea6a580a59b51ead9933e6b66" title="字面量"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>字面量</b></span></span></h4><blockquote class="notion-quote notion-block-1db6402ea6a580f6a9b1f2da6dccd955"><div>创建固定值的类型，自己创建一个类型，这个类型是固定的值，可以是多个值。</div></blockquote><div class="notion-text notion-block-1db6402ea6a580b384a4d30016ef8240"><b>字面量的使用</b></div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-1db6402ea6a5807e8fadd7a6b025ae0a" data-id="1db6402ea6a5807e8fadd7a6b025ae0a"><span><div id="1db6402ea6a5807e8fadd7a6b025ae0a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1db6402ea6a5807e8fadd7a6b025ae0a" title="交叉类型"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>交叉类型</b></span></span></h4><blockquote class="notion-quote notion-block-1db6402ea6a580a296e6c11a0cba8235"><div>对某个类型进行扩展组合成为新的类型</div></blockquote><div class="notion-text notion-block-1db6402ea6a580d7a2aed08e662e9de9"><b>类和接口的交叉类型</b></div><div class="notion-text notion-block-1db6402ea6a5802ca47cdd96c53087e4"><b>type和interface的区别</b></div><ul class="notion-list notion-list-disc notion-block-1db6402ea6a58063b66dd0831ad5e405"><li>type是某个类型的别名，当类型的名称太长或想起另一个名称时使用</li></ul><ul class="notion-list notion-list-disc notion-block-1db6402ea6a5804db396e92e667e3524"><li>interface是一个标准的类型接口</li></ul><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-1db6402ea6a580caa764ff513a6c024e" data-id="1db6402ea6a580caa764ff513a6c024e"><span><div id="1db6402ea6a580caa764ff513a6c024e" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1db6402ea6a580caa764ff513a6c024e" title="8. 内置类型"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>8. 内置类型</b></span></span></h3><div class="notion-text notion-block-1db6402ea6a58035a436f1ec76773767"><b>global objects(全局对象)</b></div><div class="notion-text notion-block-1db6402ea6a58054bb79c719f4d4e9b4"><b>build-in object(内置对象)</b></div><div class="notion-text notion-block-1db6402ea6a580c0b63be163a60987fb"><b>Dom and Bom（DOM和BOM标准对象类型</b></div><div class="notion-text notion-block-1db6402ea6a580b48aecfd07a5f633c9"><b>Utility Types(功能性类型)</b></div><div class="notion-text notion-block-1db6402ea6a580379e4bda4e506ecf1b">Partial：把传入的类型都变成可选类型</div><div class="notion-text notion-block-1db6402ea6a580ff8194f76fcb71a96a">Omit: 忽略传入的某个属性</div><div class="notion-text notion-block-1db6402ea6a5802ba5bdc7a1ff0d4410">更多Utility Types类型请查看ts官网：</div><div class="notion-text notion-block-1db6402ea6a580d9aad1e8b0528ffcab"><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://www.typescriptlang.org/docs/handbook/utility-types.html">https://www.typescriptlang.org/docs/handbook/utility-types.html</a></div><div class="notion-blank notion-block-1db6402ea6a580f0adf6f4d2826791e3"> </div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[钝感力，是生活最好的解药]]></title>
            <link>https://www.anyaoqi.cn/article/1db6402e-a6a5-803c-9f58-cfa5f17d5e39</link>
            <guid>https://www.anyaoqi.cn/article/1db6402e-a6a5-803c-9f58-cfa5f17d5e39</guid>
            <pubDate>Sun, 20 Apr 2025 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-1db6402ea6a5803c9f58cfa5f17d5e39"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-1db6402ea6a5801cbd92e6f75013e409" data-id="1db6402ea6a5801cbd92e6f75013e409"><span><div id="1db6402ea6a5801cbd92e6f75013e409" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1db6402ea6a5801cbd92e6f75013e409" title="钝感力，是生活最好的解药"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">钝感力，是生活最好的解药</span></span></h2><div class="notion-text notion-block-1db6402ea6a580e5b926d993c9f0c61a">本周读了《钝感力》这本书，刚开始看到这个书名的时候感觉不太吸引我，我看在当当热卖榜排名很高所以也想看看，在网上看了几页以后觉得很好，感觉说的跟自己很像，然后就决定买了这本书来读。现在已经看了一半，把看的时候心中的想法写一下，就当是个笔记吧。</div><blockquote class="notion-quote notion-block-1db6402ea6a5808ba4e3df391dd503a7"><div>所谓&#x27;钝感力’，即&#x27;迟钝之力’，亦即从容面对生活中的挫折伤痛，而不要过分敏感。</div></blockquote><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-1db6402ea6a580548a2cef39d1057afa" data-id="1db6402ea6a580548a2cef39d1057afa"><span><div id="1db6402ea6a580548a2cef39d1057afa" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1db6402ea6a580548a2cef39d1057afa" title="心"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">心</span></span></h3><blockquote class="notion-quote notion-block-1db6402ea6a58070a95ce30f966d696c"><div>生活中当我们遇到被别人指责、批评和谩骂的时候，我们会感觉到难过或者生气，特别是自己在乎的人，自尊心越强的人就会感觉越难过。钝感力就是可以对那些声音保持一种顿感，也就是不要有太强的自尊心，等于给自己的心加了一个盾牌，这样就会越挫越勇。</div></blockquote><div class="notion-text notion-block-1db6402ea6a58060bf15fd69d5d36617">企业家在创业的路上总会听到各种各样的声音，如果他们轻易因为别人的一句话就被影响了那肯定也不会成功。明星也经常会听到网友的指指点点，如果明星因为其他人的指指点点就整天怀疑自己也明星也做长久不了。</div><blockquote class="notion-quote notion-block-1db6402ea6a580619284d488b1553386"><div>再没有比有点才华但自尊心过强的人更难伺候的了。</div></blockquote><div class="notion-text notion-block-1db6402ea6a5803db07bc73a9975e0f5">有一个场景非常能说明钝感力的好处，就是考驾照。在练车的时候一出错驾校教练就会劈头盖脸的骂你，甚至有的骂的特别凶，无论你是小女生还是大老爷们都是一顿骂。我就是那种自尊心比较强的人，以前考驾照的时候就被骂的特别狠，我当时练车的时候心里特别难过，特别不想去练车，但是又没办法想考驾照只能去练车。我以为是我倒霉遇到的这个教练脾气不好，后来从网上看了别的学员吐槽才知道所有教练都是这样。也有一些人对教练的话就是选择忽略，他骂的时候就回复嗯，左耳朵进右耳多出。当遇到这种教练的时候就要保持一种钝感力。</div><div class="notion-text notion-block-1db6402ea6a580d98f28ff5bf2e07f17">有一种职业是最需要读这本书的，因为这种钝感力是他们必备的工作技能，这种职业就是销售。做销售的人每天都会遇到各种各样的顾客，有脾气好的可能会婉言拒绝，但遇到那种脾气不好的顾客也许会说些很难听的话，甚至有的还会故意刁难。所以很多销售团队每天早上都会喊口号互相激励，也会想各种方法锻炼员工的能力。当员工拥有了这种钝感力的时候无论再遇到什么样的顾客也可以应对自如。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-1db6402ea6a5806184acc5cc89108d63" data-id="1db6402ea6a5806184acc5cc89108d63"><span><div id="1db6402ea6a5806184acc5cc89108d63" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1db6402ea6a5806184acc5cc89108d63" title="身"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">身</span></span></h3><blockquote class="notion-quote notion-block-1db6402ea6a580478a52efa93b86a7b2"><div>对健康而言，最为重要的就是让自己全身的血液总是能够顺畅地流淌。</div></blockquote><div class="notion-text notion-block-1db6402ea6a58097b436eae63ce80b43">我们的身体也需要一种钝感力，书中用人的五官介绍了钝感力对身体的作用。我读完后觉得说的很对，人的感官太敏锐肯定也有很多好处，比如夜间开车的时候视力好就可以比别人看的更清楚一些，这样的例子很多。但是太敏锐的话也会有一些困扰，主要是看这种能力使用的场景，比如晚上睡觉的时候，听觉不好的人即使外界有些声音也不会醒，但听觉特别灵敏的人就不行，只要外面有一丁点的声音就会醒，特别是很多缺乏安全感的女生都会这样，所以身体也需要拥有钝感力。</div><div class="notion-text notion-block-1db6402ea6a5807a8c30eeb0e4db7fe0">书中通过血液的流动讲了如果没有拥有钝感力造成的负面情绪是如何影响身体健康的。保持心情舒适可以让我们的血液畅通无阻。当内心拥有钝感力会让我们的身体更健康，这样可以减少生气、难过和不开心等这种负面情绪，</div><blockquote class="notion-quote notion-block-1db6402ea6a5804fad68f813a230b1fb"><div>一旦下了决心，就能够无视周围人的目光和流言蜚语，毅然决然地进行。即使听到别人的讽刺，也是一副“与我无关”的架势，大大方方地勇往直前。这种钝感力，正是人们向崭新的领域挑战时能够获得成功的原动力。</div></blockquote><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-1db6402ea6a580e7b7d1e31c5c59f4e0" data-id="1db6402ea6a580e7b7d1e31c5c59f4e0"><span><div id="1db6402ea6a580e7b7d1e31c5c59f4e0" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1db6402ea6a580e7b7d1e31c5c59f4e0" title="个人总结"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">个人总结</span></span></h3><div class="notion-text notion-block-1db6402ea6a580929da0fb514508db26">无论是心的钝感力还是身体的钝感力我感觉都跟一个字有关系：度。</div><div class="notion-text notion-block-1db6402ea6a580baa338f394bed274b7">做任何事都有一个度，超出这个度不好，低于这个度也不好。这个度包括我们心里对别人的感受和身体对外界的感受。对别人的话不能一点不在乎，但也不用太在意，不用听了以后就整天一直想着他的话，只需要挑出别人话里的关键信息听就可以了，把一些带有情绪的话忽略掉。</div><div class="notion-blank notion-block-1db6402ea6a5808486a3eb979a8ed825"> </div><div class="notion-blank notion-block-1db6402ea6a5804c8587e9f8adca4a7b"> </div></main></div>]]></content:encoded>
        </item>
    </channel>
</rss>