{"id":347585,"date":"2023-05-17T09:02:08","date_gmt":"2023-05-17T09:02:08","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=347585"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=347585","title":{"rendered":"<span>\u0423\u0447\u0438\u043c\u0441\u044f \u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u044b\u0435 Typescript \u0442\u0438\u043f\u044b \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0440\u043e\u0443\u0442\u0438\u043d\u0433\u0430 \u0432 React<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<p>\u0412\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 TypeScript, \u043d\u043e&nbsp;\u0432\u043f\u0430\u0434\u0430\u0435\u0442\u0435 \u0432&nbsp;\u0441\u0442\u0443\u043f\u043e\u0440 \u043f\u0435\u0440\u0435\u0434, \u043a\u043e\u0433\u0434\u0430 \u0432\u0438\u0434\u0438\u0442\u0435 \u0442\u0438\u043f\u044b \u0432&nbsp;\u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u0445? Generics, generic constraint, infer, rest infer, conditional \u0438 recursive types, satisfies \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0442 \u0433\u043e\u043b\u043e\u0432\u043d\u0443\u044e \u0431\u043e\u043b\u044c? \u041c\u044b \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u0435\u043c\u0441\u044f \u0441\u043d\u0438\u0437\u0438\u0442\u044c \u0433\u0440\u0430\u0434\u0443\u0441 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0438 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0442\u0438\u043f\u044b \u0434\u043b\u044f&nbsp;\u0440\u043e\u0443\u0442\u0438\u043d\u0433\u0430 \u0432&nbsp;React. \u0414\u0430\u043d\u043d\u044b\u0439 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0435\u0437\u0435\u043d \u043a\u0430\u043a&nbsp;\u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434\u0435\u0440\u0430\u043c, \u0442\u0430\u043a \u0438 \u0431\u0435\u043a\u0435\u043d\u0434\u0435\u0440\u0430\u043c.<\/p>\n<p>\u0421\u0442\u0430\u0442\u044c\u044f \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442, \u0447\u0442\u043e&nbsp;\u0432\u044b \u0443\u0436\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u044b \u0441&nbsp;TypeScript, \u0437\u043d\u0430\u0435\u0442\u0435 \u043e\u0441\u043d\u043e\u0432\u044b \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u0432&nbsp;\u043f\u043e\u0432\u0441\u0435\u0434\u043d\u0435\u0432\u043d\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435.<\/p>\n<p>\u0412\u0441\u0435 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u0441\u043b\u043e\u0432\u0430 \u0438 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0438 TS \u0438 \u0440\u043e\u0443\u0442\u0438\u043d\u0433\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0432&nbsp;\u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435. \u0418 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0432&nbsp;\u0444\u043e\u0440\u043c\u0430\u0442\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b:<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435<\/p>\n<\/th>\n<th>\n<p>TS<\/p>\n<\/th>\n<th>\n<p>JS<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\n<\/td>\n<td>\n<p align=\"left\">\n<\/td>\n<td>\n<p align=\"left\">\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h3>\u041f\u043b\u0430\u043d<\/h3>\n<ul>\n<li>\n<p>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430<\/p>\n<\/li>\n<li>\n<p>\u0418\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b<\/p>\n<\/li>\n<li>\n<p>\u0418\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0438\u0437 path<\/p>\n<\/li>\n<li>\n<p>\u041a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438<\/p>\n<\/li>\n<li>\n<p>Satisfies, as const, type assertion<\/p>\n<\/li>\n<li>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043a \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c \u0434\u0435\u0440\u0435\u0432\u0430 \u043f\u043e\u043b\u043d\u044b\u0439 \u043f\u0443\u0442\u044c \u0434\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0435\u0434\u0438\u043d\u044f\u0435\u043c \u0432\u0441\u0435 \u0432\u043c\u0435\u0441\u0442\u0435<\/p>\n<\/li>\n<\/ul>\n<h3>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430<\/h3>\n<p>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 <strong>routing (\u0440\u043e\u0443\u0442\u0438\u043d\u0433)<\/strong>?<\/p>\n<p>\u0412 \u0434\u0432\u0443\u0445 \u0441\u043b\u043e\u0432\u0430\u0445 \u044d\u0442\u043e \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438 \u043c\u0435\u0436\u0434\u0443 \u044d\u043a\u0440\u0430\u043d\u0430\u043c\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0430\u044f \u0438\u0437:<\/p>\n<ul>\n<li>\n<p>Screen (\u044d\u043a\u0440\u0430\u043d) &#8212; \u043c\u0435\u0441\u0442\u043e \u043a\u0443\u0434\u0430 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043f\u0430\u0441\u0442\u044c, \u0432 ui-\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u0445 \u044d\u0442\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b.<\/p>\n<\/li>\n<li>\n<p>Route (\u043c\u0430\u0440\u0448\u0440\u0443\u0442, \u0440\u043e\u0443\u0442) &#8212; \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0430 \u0434\u043e \u044d\u043a\u0440\u0430\u043d\u0430, \u043c\u043e\u0436\u0435\u0442 \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0432 \u0441\u0435\u0431\u044f path, \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0438 \u0434\u0440.<\/p>\n<\/li>\n<li>\n<p>Path (\u043f\u0443\u0442\u044c) &#8212; \u043f\u0443\u0442\u044c, \u0441\u0442\u0440\u043e\u043a\u0430 \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442\u0441\u044f URL:<\/p>\n<ul>\n<li>\n<p>\u0421\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 <code>\/about<\/code>, <code>\/tasks<\/code><\/p>\n<\/li>\n<li>\n<p>\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439  <code>\/tasks\/:taskId<\/code><\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>URL &#8212; \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0430\u0434\u0440\u0435\u0441 \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e path <code>http:\/\/tutorial\/tasks\/1<\/code><\/p>\n<\/li>\n<\/ul>\n<p><em>*\u042d\u0442\u0438 \u0442\u0435\u0440\u043c\u0438\u043d\u044b \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u0430\u043b\u0435\u0435*<\/em><\/p>\n<pre><code class=\"typescript\"> \/\/ 1. \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043c\u0430\u0440\u0448\u0440\u0443\u0442 \/\/ \u041c\u0430\u0440\u0448\u0440\u0443\u0442 \u0434\u043e \u044d\u043a\u0440\u0430\u043d\u0430 &lt;Route    \/\/ \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442\u0441\u044f URL   path=\"\/tasks\/:taskId\"   \/\/ \u044d\u043a\u0440\u0430\u043d   component={Task} \/&gt; \/\/ 2. \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c URL \/\/ &lt;http:\/\/tutorial\/tasks\/1&gt; const url = generateUrl(\"\/tasks\/:taskId\", { taskId: 1 }) \/\/ 3. \u041f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043f\u043e URL navigate(url); <\/code><\/pre>\n<p>\u0412 Single Page \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445 \u0440\u043e\u0443\u0442\u0438\u043d\u0433 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0430. \u0418 \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 React \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u044f \u0440\u0430\u0431\u043e\u0442\u0430\u043b:<\/p>\n<ol>\n<li>\n<p>C\u0438\u0441\u0442\u0435\u043c\u0430 \u0440\u043e\u0443\u0442\u0438\u043d\u0433\u0430 \u0440\u0430\u0437\u0431\u0440\u043e\u0441\u0430\u043d\u0430 \u043f\u043e \u0444\u0430\u0439\u043b\u0430\u043c<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"vala\">\/\/ Tasks.tsx function Tasks() {   return (     &lt;Task path=\":taskId\" \/&gt;   ) } \/\/ App.tsx function App() {   return (     &lt;Router&gt;   &lt;Tasks path=\"tasks\" \/&gt;     &lt;Router&gt;   ) } <\/code><\/pre>\n<ol start=\"2\">\n<li>\n<p>\u041d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u044f \u043f\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044e \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0445 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442 \u0432 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 <code>to={'\/path\/to\/component}<\/code><\/p>\n<\/li>\n<\/ol>\n<p>\u0414\u0430\u0436\u0435 \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0438\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0441\u0430\u043c\u043e\u0439 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 react-router, \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u044b \u043f\u0438\u0448\u0443\u0442\u0441\u044f \u0442\u0430\u043a:<\/p>\n<pre><code class=\"typescript\">import { Outlet, Link } from \"react-router-dom\";  export default function Root() {   return (     &lt;&gt;       &lt;div id=\"sidebar\"&gt;         {\/* other elements *\/}         &lt;nav&gt;           &lt;ul&gt;             &lt;li&gt;               &lt;Link to={`contacts\/1`}&gt;Your Name&lt;\/Link&gt;             &lt;\/li&gt;             &lt;li&gt;               &lt;Link to={`contacts\/2`}&gt;Your Friend&lt;\/Link&gt;             &lt;\/li&gt;           &lt;\/ul&gt;         &lt;\/nav&gt;          {\/* other elements *\/}       &lt;\/div&gt;     &lt;\/&gt;   ); }<\/code><\/pre>\n<p>\u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u0440\u0430\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0440\u043e\u0443\u0442\u043e\u0432 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f. \u041d\u0430\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u043c\u043e\u043c\u0435\u043d\u0442 \u043a\u043e\u0433\u0434\u0430 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u044e \u0438 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0438\u0441\u043a\u0430\u0442\u044c \u0444\u0430\u0439\u043b\u044b \u0433\u0434\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u044d\u0442\u043e\u0442 \u0440\u043e\u0443\u0442 \u0438 \u043c\u0435\u043d\u044f\u0442\u044c \u0432\u0440\u0443\u0447\u043d\u0443\u044e.<\/p>\n<p>\u041d\u043e path\u2019\u044b \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0442\u0441\u044f \u043f\u043e\u043b\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u043e\u0439 <code>\/tasks\/:taskId<\/code>, \u0430 \u043c\u043e\u0433\u0443\u0442 \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c\u0441\u044f \u0438\u0437 \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445:<\/p>\n<pre><code class=\"typescript\">const tasksPath = 'tasks'; const { taskId } = useParams() generateUrl(`${tasksPath}\/:taskid, { taskId }`)<\/code><\/pre>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u043f\u0440\u0438 \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u0435 \u043c\u043e\u0436\u043d\u043e \u0447\u0442\u043e-\u0442\u043e \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c. \u0412 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u043f\u043e\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0431\u0438\u0442\u044b\u0435 \u0441\u0441\u044b\u043b\u043a\u0438 \u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u043d\u0435\u0433\u043e\u0434\u0443\u044e\u0442.<\/p>\n<h3>\u041a \u0447\u0435\u043c\u0443 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u0440\u0438\u0439\u0442\u0438<\/h3>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u0435 \u043c\u044b \u043d\u0430\u0443\u0447\u0438\u043c\u0441\u044f \u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u044b\u0435 TypeScript \u0442\u0438\u043f\u044b \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0446\u0435\u043d\u0442\u0440\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0440\u043e\u0443\u0442\u0438\u043d\u0433\u0430.<\/p>\n<p>\u0412 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 TypeScript-first routing \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <a href=\"https:\/\/type-route.zilch.dev\/\" rel=\"noopener noreferrer nofollow\">type-route<\/a>, \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u0438\u0441\u0430\u0442\u044c \u0441 \u043d\u0443\u043b\u044f. \u041a \u0442\u043e\u043c\u0443 \u0436\u0435 \u043d\u0430\u0448\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u043e \u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u043b\u044e\u0431\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 \u0440\u043e\u0443\u0442\u0438\u043d\u0433\u0430.<\/p>\n<h4>\u0427\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0432 \u0438\u0442\u043e\u0433\u0435<\/h4>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/367\/b69\/be8\/367b69be80db45d1d92b58e7c76bbb08.png\" alt=\"\u0418\u0442\u043e\u0433\u043e\u0432\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0440\u043e\u0443\u0442\u0438\u043d\u0433\u0430\" title=\"\u0418\u0442\u043e\u0433\u043e\u0432\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0440\u043e\u0443\u0442\u0438\u043d\u0433\u0430\" width=\"1808\" height=\"1592\"><\/p>\n<div><figcaption>\u0418\u0442\u043e\u0433\u043e\u0432\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0440\u043e\u0443\u0442\u0438\u043d\u0433\u0430<\/figcaption><\/div>\n<\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a0e\/666\/96e\/a0e66696e382a0c368bb9ef0dbe457f3.png\" alt=\"\u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u0438 \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f\" title=\"\u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u0438 \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f\" width=\"1974\" height=\"1116\"><\/p>\n<div><figcaption>\u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u0438 \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f<\/figcaption><\/div>\n<\/figure>\n<ul>\n<li>\n<p>\u0414\u0435\u0440\u0435\u0432\u043e \u0432\u0441\u0435\u0445 \u0440\u043e\u0443\u0442\u043e\u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432&nbsp;\u043e\u0434\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435&nbsp;\u2014 json \u043a\u043e\u043d\u0444\u0438\u0433;<\/p>\n<\/li>\n<li>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u044d\u0442\u0438 \u0440\u043e\u0443\u0442\u044b \u0438 \u0432\u0438\u0434\u0435\u0442\u044c \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0438 \u0432&nbsp;IDE;<\/p>\n<\/li>\n<li>\n<p>\u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044e \u0438\u0442\u043e\u0433\u043e\u0432\u043e\u0433\u043e URL \u043f\u043e&nbsp;path\u00bb\u0443;<\/p>\n<\/li>\n<li>\n<p>\u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043f\u0440\u0438&nbsp;\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 URL.<\/p>\n<\/li>\n<\/ul>\n<h3>\u0418\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b<\/h3>\n<p>\u0427\u0442\u043e&nbsp;\u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043c\u0438\u043c\u043e \u0441\u0430\u043c\u043e\u0433\u043e TS<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/react.dev\/\" rel=\"noopener noreferrer nofollow\">react<\/a>&nbsp;\u2014 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433\u0430;<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/sindresorhus\/type-fest\" rel=\"noopener noreferrer nofollow\">type\u2011fest<\/a>&nbsp;\u2014 \u043d\u0430\u0431\u043e\u0440 ts \u0443\u0442\u0438\u043b\u0438\u0442;<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/www.npmjs.com\/package\/expect-type\" rel=\"noopener noreferrer nofollow\">expect\u2011type<\/a>&nbsp;\u2014 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0438\u043f\u043e\u0432;<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/reactrouter.com\/en\/main\" rel=\"noopener noreferrer nofollow\">react\u2011router<\/a>&nbsp;\u2014 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0440\u043e\u0443\u0442\u0438\u043d\u0433\u0430 \u0434\u043b\u044f&nbsp;React.<\/p>\n<\/li>\n<\/ul>\n<h3>\u0418\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0438\u0437 path<\/h3>\n<p>\u0412 <a href=\"https:\/\/reactrouter.com\/en\/main\" rel=\"noopener noreferrer nofollow\">react-router<\/a> \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u0442\u0438\u043f\u044b \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438, \u043d\u043e \u043c\u044b \u043a\u043e\u043d\u0435\u0447\u043d\u043e-\u0436\u0435 \u0438\u0437\u043e\u0431\u0440\u0435\u0442\u0435\u043c \u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434.<br \/>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0442\u0438\u043f\u044b:<\/p>\n<pre><code class=\"typescript\">export type ExtractParams&lt;Path&gt; = Path extends `${infer Segment}\/${infer Rest}`   ? ExtractParam&lt;Segment&gt; &amp; ExtractParams&lt;Rest&gt;   : ExtractParam&lt;Path&gt;  \/\/ \u041f\u0440\u0438\u043c\u0435\u0440  type Params = ExtractParams&lt;'\/tasks\/:taskId\/:commentId'&gt;  \/\/ Params = { taskId: string; commentId: string; }  export type ExtractParam&lt;Segment&gt; = Segment extends `:${infer Param}`   ? {     [Param]: string;   }   : unknown;  \/\/ \u041f\u0440\u0438\u043c\u0435\u0440 type Param = ExtractParam&lt;':taskId'&gt; \/\/ Param = { taskId: string; }<\/code><\/pre>\n<p>\u042d\u0442\u0438 \u0434\u0432\u0430 \u0442\u0438\u043f\u0430&nbsp;\u2014 \u043e\u0441\u043d\u043e\u0432\u0430 \u0434\u043b\u044f&nbsp;\u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0438 IDE suggestions \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043f\u0440\u0438&nbsp;\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 URL \u043d\u0430&nbsp;\u043e\u0441\u043d\u043e\u0432\u0435 path:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/067\/f6d\/b18\/067f6db187cfcfa49d48814870ca8e5d.png\" alt=\"\u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f\" title=\"\u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f\" width=\"2488\" height=\"716\"><\/p>\n<div><figcaption>\u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f<\/figcaption><\/div>\n<\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f4e\/fdc\/36b\/f4efdc36b6de48fa8aa07764a1d4dd78.png\" alt=\"IDE-suggestions\" title=\"IDE-suggestions\" width=\"1590\" height=\"538\"><\/p>\n<div><figcaption>IDE-suggestions<\/figcaption><\/div>\n<\/figure>\n<h4>ExtractParam<\/h4>\n<p>\u041d\u0430\u043f\u043e\u043c\u043d\u044e, \u0447\u0442\u043e&nbsp;path&nbsp;\u2014 \u044d\u0442\u043e \u0441\u0442\u0440\u043e\u043a\u0430 <code>\/segment\/:parameterSegment\/segement2<\/code> \u043f\u043e&nbsp;\u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0438\u0442\u043e\u0433\u043e\u0432\u044b\u0439 URL. \u0421\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437&nbsp;\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u043e\u0432:<\/p>\n<ul>\n<li>\n<p><code>:parameterSegment<\/code>&nbsp;\u2014 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043d\u0430&nbsp;\u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432&nbsp;URL;<\/p>\n<\/li>\n<li>\n<p><code>segment<\/code>&nbsp;\u2014 \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u0430\u044f \u0447\u0430\u0441\u0442\u044c;<\/p>\n<\/li>\n<li>\n<p><code>\/<\/code>&nbsp;\u2014 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u044e\u0449\u0438\u0439 \u0441\u043b\u0435\u0448.<\/p>\n<\/li>\n<\/ul>\n<p>\u0420\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u043f\u0435\u0440\u0432\u044b\u0439 \u0442\u0438\u043f <code>ExtractParam<\/code>. \u041e\u043d \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0430 \u0441&nbsp;\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c \u0432 <code>object type<\/code> \u0441&nbsp;\u0442\u0430\u043a\u0438\u043c&nbsp;\u0436\u0435 \u043a\u043b\u044e\u0447\u043e\u043c<\/p>\n<pre><code class=\"typescript\">export type ExtractParam&lt;Path&gt; = Path extends `:${infer Param}`   ? {     [Param]: string;   }   : {};  \/\/ expectTypeOf - \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 expect-type \/\/ @ts-expect-error - \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439 \u0438\u0437 expect-type \u043d\u0430\u043f\u043e\u0434\u043e\u0431\u0438\u0438 eslint-disable-next-line it('ExtractParam type ', () =&gt; {   \/\/ { taskId: string }    expectTypeOf({ taskId: '' })     .toMatchTypeOf&lt;ExtractParam&lt;':taskId'&gt;&gt;();      \/\/ { commentId: string }    expectTypeOf({ commentId: '' })     .toMatchTypeOf&lt;ExtractParam&lt;':commentId'&gt;&gt;();      \/\/ {} \u0432\u0442\u043e\u0440\u0430\u044f \u0432\u0435\u0442\u043a\u0430 conditional   expectTypeOf({ }).toMatchTypeOf&lt;ExtractParam&lt;'somestring'&gt;&gt;();       \/\/ @ts-expect-error    \/\/ !== { taskId: number }     expectTypeOf({ taskId: 1 }).toMatchTypeOf&lt;ExtractParam&lt;':taskId'&gt;&gt;();      \/\/ @ts-expect-error    \/\/ !== { }   expectTypeOf({ }).toEqualTypeOf&lt;ExtractParam&lt;':taskId'&gt;&gt;(); });<\/code><\/pre>\n<p>\u0414\u043b\u044f&nbsp;\u043e\u0431\u043b\u0435\u0433\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0435\u0440\u0435\u0432\u0435\u0434\u0435\u043c \u0442\u0438\u043f <code>ExtractParam<\/code> \u0432&nbsp;\u043f\u0441\u0435\u0432\u0434\u043e\u043a\u043e\u0434 \u043d\u0430&nbsp;JS.<\/p>\n<p><em>(* \u042f \u043d\u0435&nbsp;\u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u044e, \u0447\u0442\u043e&nbsp;\u043f\u043e\u0434&nbsp;\u043a\u0430\u043f\u043e\u0442\u043e\u043c \u043e\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a)<br \/>(** \u0414\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u044f \u043f\u043e\u0437\u0430\u0438\u043c\u0441\u0442\u0432\u043e\u0432\u0430\u043b \u0438\u0437&nbsp;\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <\/em><a href=\"https:\/\/github.com\/mistlog\/typetype\" rel=\"noopener noreferrer nofollow\"><em>type\u2011type<\/em><\/a><em>, \u043e\u043d\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u0432&nbsp;JS\u2011like \u043d\u043e\u0442\u0430\u0446\u0438\u0438)<\/em><\/p>\n<pre><code class=\"typescript\">export const extractParam = (path: any) =&gt; {   if (typeof path === \"string\" &amp;&amp; path.startsWith(':')) {    const param = path.slice(1);     return {     [param]: '',    }   }   else {     return {}   } }  it('extractParam func', function () {   expect(extractParam(':taskId')).toEqual({ taskId: '' });   expect(extractParam('taskId')).toEqual({ }); });<\/code><\/pre>\n<p>\u0412&nbsp;\u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u044b \u0432\u0441\u0435\u043c \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u043c \u0441\u043b\u043e\u0432\u0430\u043c \u0438 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044f\u043c:<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th data-colwidth=\"213\" width=\"213\">\n<p>\u041a\u043e\u043d\u0446\u0435\u043f\u0442<\/p>\n<\/th>\n<th data-colwidth=\"262\" width=\"262\">\n<p>TS<\/p>\n<\/th>\n<th>\n<p>JS<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td data-colwidth=\"213\" width=\"213\">\n<p align=\"left\"><strong>Property mapping<\/strong><\/p>\n<\/td>\n<td data-colwidth=\"262\" width=\"262\">\n<p align=\"left\"><code>{<br \/> [Param]: string;<br \/>}<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>{   <br \/>  [param]: ''<br \/>}<\/code><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"213\" width=\"213\">\n<p align=\"left\"><a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/2\/generics.html\" rel=\"noopener noreferrer nofollow\"><strong>GENERICS<\/strong><\/a><strong><br \/><\/strong>\u041e\u0431\u043e\u0431\u0449\u0435\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u044b &#8212; \u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0438\u0435 \u043d\u0430 \u0432\u0445\u043e\u0434 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440<\/p>\n<\/td>\n<td data-colwidth=\"262\" width=\"262\">\n<p align=\"left\"><code>type ExtractParam&lt;Path&gt;<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>const extractParam = (path: any)<\/code><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"213\" width=\"213\">\n<p align=\"left\"><a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/2\/generics.html#generic-constraints\" rel=\"noopener noreferrer nofollow\"><strong>GENERICS CONSTRAINTS<\/strong><\/a><strong><br \/><\/strong>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u043e\u0431\u044b\u0447\u043d\u044b\u043c \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u043c, \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0430 \u0442\u043e \u0447\u0442\u043e \u0432\u0445\u043e\u0434\u043d\u043e\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0438\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0443 \u0441\u0442\u0440\u043e\u043a<\/p>\n<\/td>\n<td data-colwidth=\"262\" width=\"262\">\n<p align=\"left\"><code>if (typeof path === \"string\" &amp;&amp; path.startsWith(':'))<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>Path extends ':${infer Param}'<\/code><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"213\" width=\"213\">\n<p align=\"left\"><a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/2\/conditional-types.html\" rel=\"noopener noreferrer nofollow\"><strong><em>CONDITIONAL TYPES<\/em><\/strong><\/a><strong><br \/><\/strong>\u0423\u0441\u043b\u043e\u0432\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u043e\u0431\u044b\u0447\u043d\u043e\u043c\u0443 if-else \u0431\u043b\u043e\u043a\u0443, \u043b\u0438\u0431\u043e \u0442\u0435\u0440\u043d\u0430\u0440\u043d\u043e\u043c\u0443 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0443<\/p>\n<\/td>\n<td data-colwidth=\"262\" width=\"262\">\n<p align=\"left\"><code>Path extends ':${infer Param}'<br \/> ? {<br \/> [Param]: string;<br \/> }<br \/> : {};<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>if (condition) { <br \/>}<br \/>else {<br \/> return {}<br \/>}<br \/><\/code> <\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"213\" width=\"213\">\n<p align=\"left\"><a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/release-notes\/typescript-2-8.html#type-inference-in-conditional-types\" rel=\"noopener noreferrer nofollow\"><strong>INFER<\/strong><\/a><br \/> \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044e \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043f\u043e\u0441\u043b\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u0430 <code>:<\/code><br \/>* \u041c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432 generic constraints<br \/> <em>** \u0415\u0441\u043b\u0438 TS \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0442\u0438\u043f \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0441\u043b\u0435 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430, \u0442\u043e \u043e\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 unknown<\/em><\/p>\n<\/td>\n<td data-colwidth=\"262\" width=\"262\">\n<p align=\"left\"><code>Path extends ':${infer Param}'<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>const param = path.slice(1);<\/code><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h4>ExtractParams<\/h4>\n<p>\u0422\u0438\u043f <code>ExtractParams<\/code> \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 path \u0432&nbsp;\u043e\u0431\u044a\u0435\u043a\u0442 \u0433\u0434\u0435 \u043a\u043b\u044e\u0447\u0438 \u044d\u0442\u043e \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u044b \u0441&nbsp;\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438, \u0430&nbsp;\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0442\u0438\u043f <code>string<\/code><\/p>\n<pre><code class=\"typescript\">export type ExtractParams&lt;Path&gt; = Path extends `${infer Segment}\/${infer Rest}`   ? ExtractParam&lt;Segment&gt; &amp; ExtractParams&lt;Rest&gt;    : ExtractParam&lt;Path&gt;  it('ExtractParams', () =&gt; {   \/\/ { taskId: string; }   expectTypeOf({ taskId: '' })   .toMatchTypeOf&lt;ExtractParams&lt;'\/:taskId'&gt;&gt;();        \/\/ \u0420\u0435\u043a\u0443\u0440\u0441\u0438\u044f ( {} &amp; { taskId: string } &amp; { tab: string } )   \/\/ { taskId: string; tab: string; }   expectTypeOf({ taskId: '', tab: '' })     .toMatchTypeOf&lt;ExtractParams&lt;'\/tasks\/:taskId\/:tab'&gt;&gt;();      \/\/ \u0420\u0435\u043a\u0443\u0440\u0441\u0438\u044f ( {} &amp; {} &amp; {} )   \/\/ { }    expectTypeOf({ }).toEqualTypeOf&lt;ExtractParams&lt;'\/path\/without\/params'&gt;&gt;();   \/\/ @ts-expect-error   \/\/ { taskId: number; }   expectTypeOf({ taskId: 1 }).toMatchTypeOf&lt;ExtractParams&lt;'\/:taskId'&gt;&gt;(); }) <\/code><\/pre>\n<pre><code class=\"typescript\">export const extractParams = (path: string): Record&lt;string, string&gt; =&gt; {   const firstSlash = path.indexOf('\/');   \/\/ \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u043f\u0440\u0435\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0438   if (firstSlash === -1) {     return extractParam(path);   }   \/\/ \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u043c \u043f\u0435\u0440\u0432\u044b\u0439 \u0441\u0435\u0433\u043c\u0435\u043d\u0442 \u0438 \u043e\u0441\u0442\u0430\u0432\u0448\u0443\u044e\u0442\u0441\u044f \u0441\u0442\u0440\u043e\u043a\u0443   \/\/ \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 [segment, rest] = ['tasks', ':taskId']   const [segment, rest] = [path.slice(0, firstSlash), path.slice(firstSlash + 1)];   return {     ...extractParam(segment),     \/\/ \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432      ...extractParams(rest)   } }  it('extractParams func', function () {   expect(extractParams('\/:taskId')).toEqual({ taskId: '' });   expect(extractParams('\/tasks\/:taskId\/:tab')).toEqual({ taskId: '', tab: '' });   expect(extractParams('\/path\/without\/params')).toEqual({ }); });<\/code><\/pre>\n<p>\u0417\u0430\u043c\u0435\u0442\u0438\u043c, \u0447\u0442\u043e&nbsp;\u0437\u0434\u0435\u0441\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f <a href=\"https:\/\/www.typescriptlang.org\/play#example\/recursive-type-references\" rel=\"noopener noreferrer nofollow\"><strong>Recursive types<\/strong><\/a> . \u0415\u0441\u043b\u0438 \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u0442\u044c \u043a\u0430\u043a&nbsp;\u0443\u0441\u0442\u0440\u043e\u0435\u043d\u044b \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<ul>\n<li>\n<p>\u041e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/p>\n<\/li>\n<li>\n<p>\u0423\u0441\u043b\u043e\u0432\u0438\u0435 \u043f\u0440\u0435\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0438<\/p>\n<\/li>\n<li>\n<p>\u0420\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432<\/p>\n<\/li>\n<\/ul>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th data-colwidth=\"148\" width=\"148\">\n<p>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435<\/p>\n<\/th>\n<th data-colwidth=\"286\" width=\"286\">\n<p>TS<\/p>\n<\/th>\n<th>\n<p>JS<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td data-colwidth=\"148\" width=\"148\">\n<p align=\"left\">\u041e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435<\/p>\n<\/td>\n<td data-colwidth=\"286\" width=\"286\">\n<p align=\"left\"><code>type ExtractParams&lt;Path&gt;<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>const extractParams<\/code><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"148\" width=\"148\">\n<p align=\"left\">\u0423\u0441\u043b\u043e\u0432\u0438\u0435 \u043f\u0440\u0435\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0438<\/p>\n<\/td>\n<td data-colwidth=\"286\" width=\"286\">\n<p align=\"left\"><code>Path extends \u2018${infer Segment}\/${infer Rest}\u2019<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>const firstSlash = path.indexOf('\/');<br \/> if (firstSlash === -1) {<br \/>   return extractParam(path);<br \/> }<\/code><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"148\" width=\"148\">\n<p align=\"left\">\u0420\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432<\/p>\n<\/td>\n<td data-colwidth=\"286\" width=\"286\">\n<p align=\"left\"><code>ExtractParam&lt;Segment&gt; &amp; ExtractParams&lt;Rest&gt;<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>{<br \/> ...extractParam(segment),<br \/> ...extractParams(rest)<br \/> }<\/code><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h3>\u041a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438<\/h3>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/262\/39c\/502\/26239c502b379c2ee31a593168847701.png\" alt=\"\u0424\u043e\u0440\u043c\u0430\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f\" title=\"\u0424\u043e\u0440\u043c\u0430\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f\" width=\"1976\" height=\"1110\"><\/p>\n<div><figcaption>\u0424\u043e\u0440\u043c\u0430\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f<\/figcaption><\/div>\n<\/figure>\n<p>\u0412&nbsp;react\u2011router \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f&nbsp;\u0434\u0435\u0440\u0435\u0432\u0430 \u0440\u043e\u0443\u0442\u0438\u043d\u0433\u0430 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 json \u043e\u0431\u044a\u0435\u043a\u0442.<\/p>\n<p>\u0414\u043b\u044f&nbsp;\u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0434\u0435\u0440\u0435\u0432\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043c\u0430\u0441\u0441\u0438\u0432 children.<\/p>\n<p>\u041d\u043e&nbsp;\u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0432&nbsp;\u0442\u043e\u043c, \u0447\u0442\u043e&nbsp;\u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043f\u043e&nbsp;\u0438\u043d\u0434\u0435\u043a\u0441\u0443 <code>children[0].fullPath<\/code>&nbsp;\u2014 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c.<\/p>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432\u044b children \u0432&nbsp;\u0434\u0435\u0440\u0435\u0432\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u043e\u043b\u043d\u044b\u0439 \u043f\u0443\u0442\u044c \u0434\u043e&nbsp;\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/30f\/f7b\/007\/30ff7b007477a50364f1a70fc335f585.png\" alt=\"\u0421\u0445\u0435\u043c\u0430 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f JS \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432\" title=\"\u0421\u0445\u0435\u043c\u0430 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f JS \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432\" width=\"1982\" height=\"1106\"><\/p>\n<div><figcaption>\u0421\u0445\u0435\u043c\u0430 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f JS \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432<\/figcaption><\/div>\n<\/figure>\n<p><strong>\u0414\u0430\u043d\u043e:<\/strong><\/p>\n<ul>\n<li>\n<p>\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0440\u043e\u0443\u0442\u0430 \u0438\u0437 react-router;<\/p>\n<\/li>\n<li>\n<p>\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u0440\u043e\u0443\u0442\u0438\u043d\u0433\u0430 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u044d\u0442\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430;<\/p>\n<\/li>\n<li>\n<p>\u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0438\u0440\u0443\u044e\u0449\u0430\u044f \u0438\u0441\u0445\u043e\u0434\u043d\u0443\u044e \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u0432 \u043d\u0443\u0436\u043d\u044b\u0439 \u043d\u0430\u043c \u0432\u0438\u0434.<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u041d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435:<\/strong><\/p>\n<p>\u041c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u043c \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0442\u044c \u043f\u0443\u0442\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c<code>ROUTES.tasks.task.fullPath<\/code> = <code>\/tasks\/:taskId<\/code><\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/111\/703\/ea6\/111703ea61c6af25a92054f6b472449a.png\" alt=\"\u0421\u0445\u0435\u043c\u0430 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f TS \u0442\u0438\u043f\u043e\u0432\" title=\"\u0421\u0445\u0435\u043c\u0430 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f TS \u0442\u0438\u043f\u043e\u0432\" width=\"1966\" height=\"1106\"><\/p>\n<div><figcaption>\u0421\u0445\u0435\u043c\u0430 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f TS \u0442\u0438\u043f\u043e\u0432<\/figcaption><\/div>\n<\/figure>\n<p>\u0421 \u0442\u0438\u043f\u0430\u043c\u0438 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435: \u043a \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0443 <code>RouteObject<\/code> \u0438\u0437 react-router \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c <code>fullPath<\/code> \u0441 \u043f\u043e\u043b\u043d\u044b\u043c \u043f\u0443\u0442\u0435\u043c \u0434\u043e \u044d\u043a\u0440\u0430\u043d\u0430 \u0438 \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c <code>path<\/code> \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443, \u043d\u0430 path \u0433\u0434\u0435 \u0431\u0443\u0434\u0435\u0442 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u043d\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0438\u0437 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"typescript\">path: ':taskId' fullPath: '\/tasks\/:taskId'<\/code><\/pre>\n<h3>Satisfies, as const, type assertion<\/h3>\n<pre><code class=\"typescript\">\/\/ \u0418\u0441\u0445\u043e\u0434\u043d\u0430\u044f \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f export const ROUTES_CONFIG = {   id: 'root',   path: '',   element: &lt;App\/&gt;,   children: [{     path: 'tasks',     id: 'tasks',     element: &lt;Tasks \/&gt;,     children: [       { path: ':taskId',  id: 'task' }     ]   }] } as const satisfies ReadonlyDeep&lt;RouteObject&gt;;<\/code><\/pre>\n<p>\u041f\u0435\u0440\u0432\u044b\u0435 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u0441\u043b\u043e\u0432\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u043c \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u043b\u0438\u0441\u044c <a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/release-notes\/typescript-4-9.html#the-satisfies-operator\" rel=\"noopener noreferrer nofollow\"><strong>satisfies<\/strong><\/a> \u0438 <a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/release-notes\/typescript-3-4.html#const-assertions\" rel=\"noopener noreferrer nofollow\"><strong>as const<\/strong><\/a> \u044d\u0442\u043e \u0444\u0443\u043d\u0434\u0430\u043c\u0435\u043d\u0442 \u043d\u0430&nbsp;\u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0434\u0435\u0440\u0436\u0430\u0442\u0441\u044f \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0442\u0438\u043f\u044b.<\/p>\n<p><a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/2\/everyday-types.html#type-assertions\" rel=\"noopener noreferrer nofollow\"><strong>Type assertion<\/strong><\/a> (\u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u043e\u0432)&nbsp;\u2014 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e <code>as<\/code>.<\/p>\n<pre><code class=\"typescript\">interface User {   id: number;   name: string; } \/\/ any -&gt; User const typeUser = user as User;<\/code><\/pre>\n<p>\u041a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e <code>as const<\/code> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0432 \u0442\u0430\u043a\u043e\u0439 \u0436\u0435 \u0442\u0438\u043f<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/264\/58d\/d2c\/26458dd2ca01746a0ccbaca4dad61259.png\" alt=\"\u041f\u0440\u0438\u043c\u0435\u0440 as const \u0438 satisfies\" title=\"\u041f\u0440\u0438\u043c\u0435\u0440 as const \u0438 satisfies\" width=\"3576\" height=\"1248\"><\/p>\n<div><figcaption>\u041f\u0440\u0438\u043c\u0435\u0440 as const \u0438 satisfies<\/figcaption><\/div>\n<\/figure>\n<p><code>Satisfies<\/code> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u0430\u043b\u0438\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u0435\u0442 \u043a\u0430\u043a\u043e\u043c\u0443-\u0442\u043e \u0442\u0438\u043f\u0443. <strong>\u041d\u043e \u043d\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u043d\u0435\u043c\u0443.<\/strong> \u0412 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u044b \u043d\u0435 \u0442\u0435\u0440\u044f\u0435\u043c \u0442\u0438\u043f <code>as const<\/code> \u043d\u043e \u0432 \u0442\u043e\u0436\u0435 \u0432\u0440\u0435\u043c\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0447\u0442\u043e\u0431\u044b \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435 \u043d\u0435 \u0431\u044b\u043b\u043e \u043d\u0438\u0447\u0435\u0433\u043e \u043b\u0438\u0448\u043d\u0435\u0433\u043e.<\/p>\n<h3>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043a \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c \u0434\u0435\u0440\u0435\u0432\u0430 \u043f\u043e\u043b\u043d\u044b\u0439 \u043f\u0443\u0442\u044c \u0434\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430<\/h3>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0442\u0438\u043f\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f \u043f\u043e\u0437\u0436\u0435:<\/p>\n<pre><code class=\"typescript\">type ConstantRoute&lt;   FullPath extends string,   Path extends string &gt; = Omit&lt;RouteObject, 'path'&gt; &amp; {   path: CurrentPath;   fullPath: FullPath; }; type ConcatPath&lt;   Path extends string,    CurrentPath extends string&gt; = `${Path}\/${CurrentPath}`;<\/code><\/pre>\n<ul>\n<li>\n<p><code>ConcatPath<\/code> \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0435\u0442 \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u044b path c \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043b\u0435\u0448\u0430<\/p>\n<\/li>\n<li>\n<p><code>ConstantRoute<\/code> \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0434\u0432\u0435 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 <code>object type<\/code> \u0441 \u043a\u043b\u044e\u0447\u0430\u043c\u0438 <code>path<\/code>, <code>fullPath<\/code> \u0433\u0434\u0435 \u0431\u0443\u0434\u0443\u0442 \u043b\u0435\u0436\u0430\u0442\u044c \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b \u0441\u0442\u0440\u043e\u043a<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c \u044d\u0442\u0438 \u0442\u0438\u043f\u044b \u0432 \u0442\u0430\u043a\u0438\u0435 \u0436\u0435 JS \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/p>\n<pre><code class=\"typescript\">export const constantRoute = (path: string, fullPath: string): {   path: string;   fullPath: string; } =&gt; ({   path,   fullPath, })  function concatPath(fullPath: string, path: string) {   return replaceTrailingSlash(`${fullPath}\/${path}`); }<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043d\u0430\u043f\u043e\u043c\u043d\u044e, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u0441 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0435\u0439 <code>ROUTES_CONFIG<\/code> \u0438 \u0441\u0430\u043c\u043e\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0438\u043f \u043e\u0431\u044a\u0435\u043a\u0442\u0430  \u0432 \u0442\u0430\u043a\u043e\u0439 \u0436\u0435 \u0442\u0438\u043f \u0441 \u043f\u043e\u043b\u043d\u044b\u043c\u0438 \u043f\u0443\u0442\u044f\u043c\u0438.<\/p>\n<pre><code class=\"typescript\">export const ROUTES_CONFIG = {   id: 'root',   path: '',   element: &lt;App\/&gt;,   children: [{     path: 'tasks',     id: 'tasks',     element: &lt;Tasks \/&gt;,     children: [       { path: ':taskId',  id: 'task' }     ]   }] } as const satisfies ReadonlyDeep&lt;RouteObject&gt;; <\/code><\/pre>\n<p>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u043f\u0440\u043e\u0439\u0442\u0438 \u043f\u043e \u044d\u0442\u043e\u043c\u0443 \u0434\u0435\u0440\u0435\u0432\u0443 \u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c<\/p>\n<p><strong>\u0411\u044b\u043b\u043e:<\/strong><\/p>\n<pre><code class=\"typescript\">{   children: [{     path: 'tasks',     id: 'tasks',     children: [{          path: ':taskId',          id: 'task'      }]   }] }<\/code><\/pre>\n<p><strong>\u0421\u0442\u0430\u043b\u043e:<\/strong><\/p>\n<pre><code class=\"typescript\">{   tasks: {     path: 'tasks',     fullPath: 'tasks',     task: {       path: ':taskId',       fullPath: '\/tasks\/:taskId'     }   } } <\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043d\u0430\u043c \u043f\u043e\u043c\u043e\u0433\u0443\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0442\u0438\u043f\u044b:<\/p>\n<pre><code class=\"typescript\">type MergeArrayOfObjects&lt;T, Path extends string = ''&gt; =   T extends readonly [infer R, ...infer Rest]     ? RecursiveValues&lt;R, Path&gt; &amp; MergeArrayOfObjects&lt;Rest, Path&gt;     : unknown;  type RecursiveTransform&lt;   T,   Path extends string = '' &gt; = \/* \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0442\u0438\u043f\u0430 *\/<\/code><\/pre>\n<p>\u041f\u0435\u0440\u0432\u044b\u043c \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c <code>MergeArrayOfObjects<\/code> , \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432:<\/p>\n<pre><code class=\"typescript\">type MergeArrayOfObjects&lt;T, Path extends string = ''&gt; =   T extends readonly [infer R, ...infer Rest]     ? RecursiveValues&lt;R, Path&gt; &amp; MergeArrayOfObjects&lt;Rest, Path&gt;     : unknown; <\/code><\/pre>\n<pre><code class=\"typescript\">export function mergeArrayOfObjects(arr: RouteObject[], path = '') {   if (Array.isArray(arr)) {     return;   }   const [first, ...rest] = arr;   if (first == null) {     return {}   }   return {       ...recursiveValues(first, path),       ...mergeArrayOfObjects(rest, path),   }; } <\/code><\/pre>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th data-colwidth=\"234\" width=\"234\">\n<p>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435<\/p>\n<\/th>\n<th>\n<p>TS<\/p>\n<\/th>\n<th>\n<p>JS<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td data-colwidth=\"234\" width=\"234\">\n<p align=\"left\"><strong>Rest Infer<br \/><\/strong>\u0420\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043e\u043d \u0442\u0430\u043a\u0436\u0435 \u043a\u0430\u043a \u0438 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 spread<\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>[infer R, ...infer Rest]<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>const [first, ...rest] = arr<\/code><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"234\" width=\"234\">\n<p align=\"left\">\u0423\u0441\u043b\u043e\u0432\u0438\u0435 \u043f\u0440\u0435\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0438<\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>T extends readonly [infer R, ...infer Rest]<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>if (first == null) {<br \/>  return {}<br \/>}<\/code><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u041e\u043f\u0438\u0448\u0435\u043c \u0448\u0430\u0433\u0438 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0438:<\/p>\n<pre><code class=\"typescript\">const routeArr = [   { id: 'tasks', path: '\/tasks' },    { id: 'home', path: '\/home' } ]; expectTypeOf(routeArr).toMatchTypeOf&lt;MergeArrayOfObjects&lt;typeof routeArr&gt;&gt;(); \/\/ 1 \u0448\u0430\u0433 T = typeof routeArr \/\/ T extends readonly [infer R, ...infer Rest] === true R = { id: 'tasks'; path: '\/tasks' } Rest = [{ id: 'home', path: '\/home' }] \/\/ R != unknown === true MergeArrayOfObjects&lt;Rest, Path&gt; \/\/ 2 \u0448\u0430\u0433 T = [{ id: 'home', path: '\/home' }] \/\/ T extends readonly [infer R, ...infer Rest] === true R = { id: 'home'; path: '\/home' } Rest = [] \/\/ R != unknown === true MergeArrayOfObjects&lt;Rest, Path&gt; \/\/ 3 \u0448\u0430\u0433 T = []  \/\/ T extends readonly [infer R, ...infer Rest] === true R = null Rest = null \/\/ R != unknown === false \/\/ \u041e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u0435 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0438<\/code><\/pre>\n<p>\u0420\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u0442\u0438\u043f:<\/p>\n<pre><code class=\"typescript\"> \/\/ \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u043c \u0447\u0442\u043e \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 id \u0438 path, \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b \u0441\u0442\u0440\u043e\u043a \/\/ \u0438 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c  \/\/ { id: 'tasks', children: [{ id: 'task' }] } \/\/ -&gt; {tasks: { task: {} }} type RecursiveTransform&lt;   RouteObject,   FullPath extends string = '' &gt; = RouteObject extends {   id: infer Name extends string;   path: infer Path extends string; }    ? TransformIdToProperty&lt;Name, RouteObject, Path, FullPath&gt;   : { }   type TransformIdToProperty&lt;   ID extends string,   RouteObject,   Path extends string,   FullPath extends string,   \/\/ \u0432\u043a\u0440\u0430\u0442\u0446\u0435 const = concatPath(fullPath,path), \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0432\u043c\u0435\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439   ConcatedPath extends string = ConcatPath&lt;FullPath, Path&gt; &gt; = {   \/\/ \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043d\u0430\u043b\u0438\u0447\u0438\u0435 children    [Prop in ID]: RouteObject extends { children: infer Children }     \/\/ \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c      ? MergeArrayOfObjects&lt;Children, ConcatedPath&gt; &amp; ConstantRoute&lt;ConcatedPath, Path&gt;     : ConstantRoute&lt;ConcatedPath, Path&gt; } <\/code><\/pre>\n<h3>\u0421\u043e\u0435\u0434\u0438\u043d\u044f\u0435\u043c \u0432\u0441\u0435 \u0432\u043c\u0435\u0441\u0442\u0435<\/h3>\n<pre><code class=\"typescript\">export const ROUTES_CONFIG = {   id: 'root',   path: '',   element: &lt;App\/&gt;,   children: [{     path: 'tasks',     id: 'tasks',     element: &lt;Tasks \/&gt;,     children: [       { path: ':taskId',  id: 'task' }     ]   }] } as const satisfies ReadonlyDeep&lt;RouteObject&gt;;  type RoutesConfigType = typeof RecursiveTransform;  const transfromRoutes = (config: RouteObject, fullPath = '') =&gt; {   \/\/ transform code    return config as RecursiveTransform&lt;RoutesConfigType&gt; }  const ROUTES = transfromRoutes(ROUTES_CONFIG);  \/\/ ROUTES type and ROUTES object \u0438\u043c\u0435\u044e\u0442 \u0438\u0442\u043e\u0433\u043e\u0432\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 ROUTES = {   root: {     tasks: {       path: 'tasks',       fullPath: 'tasks',       task: {         path: ':taskId',         fullPath: '\/tasks\/:taskId'       }     }   } }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442:<\/p>\n<pre><code class=\"typescript\">\/\/ to='\/' &lt;Link to={ROUTES.root.fullPath}&gt;Home&lt;\/Link&gt; \/\/ to='\/tasks &lt;Link to={ROUTES.root.tasks.fullPath}&gt;Tasks&lt;\/Link&gt;  &lt;Link   \/\/ to='tasks\/1'   to={generatePath(     ROUTES.root.tasks.task.fullPath,     {       taskId: item.id.toString(),     }   )}&gt;   {item.name} &lt;\/Link&gt;<\/code><\/pre>\n<h3>\u0412 \u0438\u0442\u043e\u0433\u0435 \u043c\u044b \u043d\u0430\u0443\u0447\u0438\u043b\u0438\u0441\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c<\/h3>\n<ul>\n<li>\n<p>Generics (<a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/2\/generics.html\" rel=\"noopener noreferrer nofollow\">https:\/\/www.typescriptlang.org\/docs\/handbook\/2\/generics.html<\/a>)<\/p>\n<\/li>\n<li>\n<p>Generic constraints (<a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/2\/generics.html#generic-constraints\" rel=\"noopener noreferrer nofollow\">https:\/\/www.typescriptlang.org\/docs\/handbook\/2\/generics.html#generic-constraints<\/a>)<\/p>\n<\/li>\n<li>\n<p>Conditional Types (<a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/2\/conditional-types.html\" rel=\"noopener noreferrer nofollow\">https:\/\/www.typescriptlang.org\/docs\/handbook\/2\/conditional-types.html<\/a>)<\/p>\n<\/li>\n<li>\n<p>Infer \/Rest infer (<a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/release-notes\/typescript-2-8.html#type-inference-in-conditional-types\" rel=\"noopener noreferrer nofollow\">https:\/\/www.typescriptlang.org\/docs\/handbook\/release-notes\/typescript-2-8.html#type-inference-in-conditional-types<\/a>)<\/p>\n<\/li>\n<li>\n<p>Recursive types (<a href=\"https:\/\/www.typescriptlang.org\/play#example\/recursive-type-references\" rel=\"noopener noreferrer nofollow\">https:\/\/www.typescriptlang.org\/play#example\/recursive-type-references<\/a>)<\/p>\n<\/li>\n<li>\n<p>Satisfies (<a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/release-notes\/typescript-4-9.html#the-satisfies-operator\" rel=\"noopener noreferrer nofollow\">https:\/\/www.typescriptlang.org\/docs\/handbook\/release-notes\/typescript-4-9.html#the-satisfies-operator<\/a>)<\/p>\n<\/li>\n<li>\n<p>As const (<a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/release-notes\/typescript-3-4.html#const-assertions\" rel=\"noopener noreferrer nofollow\">https:\/\/www.typescriptlang.org\/docs\/handbook\/release-notes\/typescript-3-4.html#const-assertions<\/a>)<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 \u0442\u0438\u043f\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0440\u043e\u0443\u0442\u0438\u043d\u0433<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e\u0437\u0434\u0440\u0430\u0432\u043b\u044f\u044e \u0432\u044b \u0434\u043e\u0448\u043b\u0438 \u0434\u043e \u043a\u043e\u043d\u0446\u0430. \u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438:<\/p>\n<p><a href=\"https:\/\/github.com\/Mozzarella123\/typescript_routing\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/Mozzarella123\/typescript_routing<\/a><\/p>\n<p>\u0414\u043b\u044f \u0442\u0435\u0445, \u043a\u0442\u043e \u0445\u043e\u0447\u0435\u0442 \u043f\u043e\u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 Typescript \u0442\u0438\u043f\u043e\u0432:<\/p>\n<p><a href=\"https:\/\/github.com\/type-challenges\/type-challenges\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/type-challenges\/type-challenges<\/a><\/p>\n<h3>\u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u043d\u043e\u0441\u0442\u0438 <\/h3>\n<p>\u0417\u0430 \u0432\u044b\u0447\u0438\u0442\u043a\u0443 \u0438 \u0440\u0435\u0434\u0430\u043a\u0442\u0443\u0440\u0443<\/p>\n<ul>\n<li>\n<p><a class=\"mention\" href=\"\/users\/ostinru\">@ostinru<\/a><\/p>\n<\/li>\n<li>\n<p><a class=\"mention\" href=\"\/users\/ValyaBuldozer\">@ValyaBuldozer<\/a><\/p>\n<\/li>\n<\/ul>\n<h3>\u0421\u0441\u044b\u043b\u043a\u0438 \u0438 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u044b<\/h3>\n<ul>\n<li>\n<p>\u0420\u043e\u0443\u0442\u0438\u043d\u0433 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 react-router (<a href=\"https:\/\/reactrouter.com\/en\/main\" rel=\"noopener noreferrer nofollow\">https:\/\/reactrouter.com\/en\/main<\/a>)<\/p>\n<\/li>\n<li>\n<p>\u0420\u043e\u0443\u0442\u0438\u043d\u0433 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 type-route (<a href=\"https:\/\/type-route.zilch.dev\/\" rel=\"noopener noreferrer nofollow\">https:\/\/type-route.zilch.dev\/<\/a>)<\/p>\n<\/li>\n<li>\n<p>Typescript \u0443\u0442\u0438\u043b\u0438\u0442\u044b type-fest (<a href=\"https:\/\/github.com\/sindresorhus\/type-fest\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/sindresorhus\/type-fest<\/a>)<\/p>\n<\/li>\n<li>\n<p>\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0432\u0446\u0438\u044f React (<a href=\"https:\/\/react.dev\/\" rel=\"noopener noreferrer nofollow\">https:\/\/react.dev\/<\/a>)<\/p>\n<\/li>\n<li>\n<p>\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f Typescript<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0430\u043a\u0442\u0438\u043a\u0430 (<a href=\"https:\/\/github.com\/type-challenges\/type-challenges\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/type-challenges\/type-challenges<\/a>)<\/p>\n<\/li>\n<li>\n<p>JS-like \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0442\u0438\u043f\u043e\u0432 (<a href=\"https:\/\/github.com\/mistlog\/typetype\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/mistlog\/typetype<\/a>)<\/p>\n<\/li>\n<li>\n<p>\u0411\u043e\u043d\u0443\u0441: \u041f\u0430\u0440\u0441\u0438\u043d\u0433JSON \u0441\u0445\u0435\u043c\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e infer (<a href=\"https:\/\/alexharri.com\/blog\/build-schema-language-with-infer\" rel=\"noopener noreferrer nofollow\">https:\/\/alexharri.com\/blog\/build-schema-language-with-infer<\/a>)<\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/735542\/\"> https:\/\/habr.com\/ru\/articles\/735542\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<p>\u0412\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 TypeScript, \u043d\u043e&nbsp;\u0432\u043f\u0430\u0434\u0430\u0435\u0442\u0435 \u0432&nbsp;\u0441\u0442\u0443\u043f\u043e\u0440 \u043f\u0435\u0440\u0435\u0434, \u043a\u043e\u0433\u0434\u0430 \u0432\u0438\u0434\u0438\u0442\u0435 \u0442\u0438\u043f\u044b \u0432&nbsp;\u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u0445? Generics, generic constraint, infer, rest infer, conditional \u0438 recursive types, satisfies \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0442 \u0433\u043e\u043b\u043e\u0432\u043d\u0443\u044e \u0431\u043e\u043b\u044c? \u041c\u044b \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u0435\u043c\u0441\u044f \u0441\u043d\u0438\u0437\u0438\u0442\u044c \u0433\u0440\u0430\u0434\u0443\u0441 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0438 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0442\u0438\u043f\u044b \u0434\u043b\u044f&nbsp;\u0440\u043e\u0443\u0442\u0438\u043d\u0433\u0430 \u0432&nbsp;React. \u0414\u0430\u043d\u043d\u044b\u0439 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0435\u0437\u0435\u043d \u043a\u0430\u043a&nbsp;\u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434\u0435\u0440\u0430\u043c, \u0442\u0430\u043a \u0438 \u0431\u0435\u043a\u0435\u043d\u0434\u0435\u0440\u0430\u043c.<\/p>\n<p>\u0421\u0442\u0430\u0442\u044c\u044f \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442, \u0447\u0442\u043e&nbsp;\u0432\u044b \u0443\u0436\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u044b \u0441&nbsp;TypeScript, \u0437\u043d\u0430\u0435\u0442\u0435 \u043e\u0441\u043d\u043e\u0432\u044b \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u0432&nbsp;\u043f\u043e\u0432\u0441\u0435\u0434\u043d\u0435\u0432\u043d\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435.<\/p>\n<p>\u0412\u0441\u0435 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u0441\u043b\u043e\u0432\u0430 \u0438 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0438 TS \u0438 \u0440\u043e\u0443\u0442\u0438\u043d\u0433\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0432&nbsp;\u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435. \u0418 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0432&nbsp;\u0444\u043e\u0440\u043c\u0430\u0442\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b:<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435<\/p>\n<\/th>\n<th>\n<p>TS<\/p>\n<\/th>\n<th>\n<p>JS<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\n<\/td>\n<td>\n<p align=\"left\">\n<\/td>\n<td>\n<p align=\"left\">\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h3>\u041f\u043b\u0430\u043d<\/h3>\n<ul>\n<li>\n<p>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430<\/p>\n<\/li>\n<li>\n<p>\u0418\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b<\/p>\n<\/li>\n<li>\n<p>\u0418\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0438\u0437 path<\/p>\n<\/li>\n<li>\n<p>\u041a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438<\/p>\n<\/li>\n<li>\n<p>Satisfies, as const, type assertion<\/p>\n<\/li>\n<li>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043a \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c \u0434\u0435\u0440\u0435\u0432\u0430 \u043f\u043e\u043b\u043d\u044b\u0439 \u043f\u0443\u0442\u044c \u0434\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0435\u0434\u0438\u043d\u044f\u0435\u043c \u0432\u0441\u0435 \u0432\u043c\u0435\u0441\u0442\u0435<\/p>\n<\/li>\n<\/ul>\n<h3>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430<\/h3>\n<p>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 <strong>routing (\u0440\u043e\u0443\u0442\u0438\u043d\u0433)<\/strong>?<\/p>\n<p>\u0412 \u0434\u0432\u0443\u0445 \u0441\u043b\u043e\u0432\u0430\u0445 \u044d\u0442\u043e \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438 \u043c\u0435\u0436\u0434\u0443 \u044d\u043a\u0440\u0430\u043d\u0430\u043c\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0430\u044f \u0438\u0437:<\/p>\n<ul>\n<li>\n<p>Screen (\u044d\u043a\u0440\u0430\u043d) &#8212; \u043c\u0435\u0441\u0442\u043e \u043a\u0443\u0434\u0430 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043f\u0430\u0441\u0442\u044c, \u0432 ui-\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u0445 \u044d\u0442\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b.<\/p>\n<\/li>\n<li>\n<p>Route (\u043c\u0430\u0440\u0448\u0440\u0443\u0442, \u0440\u043e\u0443\u0442) &#8212; \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0430 \u0434\u043e \u044d\u043a\u0440\u0430\u043d\u0430, \u043c\u043e\u0436\u0435\u0442 \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0432 \u0441\u0435\u0431\u044f path, \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0438 \u0434\u0440.<\/p>\n<\/li>\n<li>\n<p>Path (\u043f\u0443\u0442\u044c) &#8212; \u043f\u0443\u0442\u044c, \u0441\u0442\u0440\u043e\u043a\u0430 \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442\u0441\u044f URL:<\/p>\n<ul>\n<li>\n<p>\u0421\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 <code>\/about<\/code>, <code>\/tasks<\/code><\/p>\n<\/li>\n<li>\n<p>\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439  <code>\/tasks\/:taskId<\/code><\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>URL &#8212; \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0430\u0434\u0440\u0435\u0441 \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e path <code>http:\/\/tutorial\/tasks\/1<\/code><\/p>\n<\/li>\n<\/ul>\n<p><em>*\u042d\u0442\u0438 \u0442\u0435\u0440\u043c\u0438\u043d\u044b \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u0430\u043b\u0435\u0435*<\/em><\/p>\n<pre><code class=\"typescript\"> \/\/ 1. \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043c\u0430\u0440\u0448\u0440\u0443\u0442 \/\/ \u041c\u0430\u0440\u0448\u0440\u0443\u0442 \u0434\u043e \u044d\u043a\u0440\u0430\u043d\u0430 &lt;Route    \/\/ \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442\u0441\u044f URL   path=\"\/tasks\/:taskId\"   \/\/ \u044d\u043a\u0440\u0430\u043d   component={Task} \/&gt; \/\/ 2. \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c URL \/\/ &lt;http:\/\/tutorial\/tasks\/1&gt; const url = generateUrl(\"\/tasks\/:taskId\", { taskId: 1 }) \/\/ 3. \u041f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043f\u043e URL navigate(url); <\/code><\/pre>\n<p>\u0412 Single Page \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445 \u0440\u043e\u0443\u0442\u0438\u043d\u0433 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0430. \u0418 \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 React \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u044f \u0440\u0430\u0431\u043e\u0442\u0430\u043b:<\/p>\n<ol>\n<li>\n<p>C\u0438\u0441\u0442\u0435\u043c\u0430 \u0440\u043e\u0443\u0442\u0438\u043d\u0433\u0430 \u0440\u0430\u0437\u0431\u0440\u043e\u0441\u0430\u043d\u0430 \u043f\u043e \u0444\u0430\u0439\u043b\u0430\u043c<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"vala\">\/\/ Tasks.tsx function Tasks() {   return (     &lt;Task path=\":taskId\" \/&gt;   ) } \/\/ App.tsx function App() {   return (     &lt;Router&gt;   &lt;Tasks path=\"tasks\" \/&gt;     &lt;Router&gt;   ) } <\/code><\/pre>\n<ol start=\"2\">\n<li>\n<p>\u041d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u044f \u043f\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044e \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0445 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442 \u0432 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 <code>to={'\/path\/to\/component}<\/code><\/p>\n<\/li>\n<\/ol>\n<p>\u0414\u0430\u0436\u0435 \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0438\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0441\u0430\u043c\u043e\u0439 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 react-router, \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u044b \u043f\u0438\u0448\u0443\u0442\u0441\u044f \u0442\u0430\u043a:<\/p>\n<pre><code class=\"typescript\">import { Outlet, Link } from \"react-router-dom\";  export default function Root() {   return (     &lt;&gt;       &lt;div id=\"sidebar\"&gt;         {\/* other elements *\/}         &lt;nav&gt;           &lt;ul&gt;             &lt;li&gt;               &lt;Link to={`contacts\/1`}&gt;Your Name&lt;\/Link&gt;             &lt;\/li&gt;             &lt;li&gt;               &lt;Link to={`contacts\/2`}&gt;Your Friend&lt;\/Link&gt;             &lt;\/li&gt;           &lt;\/ul&gt;         &lt;\/nav&gt;          {\/* other elements *\/}       &lt;\/div&gt;     &lt;\/&gt;   ); }<\/code><\/pre>\n<p>\u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u0440\u0430\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0440\u043e\u0443\u0442\u043e\u0432 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f. \u041d\u0430\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u043c\u043e\u043c\u0435\u043d\u0442 \u043a\u043e\u0433\u0434\u0430 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u044e \u0438 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0438\u0441\u043a\u0430\u0442\u044c \u0444\u0430\u0439\u043b\u044b \u0433\u0434\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u044d\u0442\u043e\u0442 \u0440\u043e\u0443\u0442 \u0438 \u043c\u0435\u043d\u044f\u0442\u044c \u0432\u0440\u0443\u0447\u043d\u0443\u044e.<\/p>\n<p>\u041d\u043e path\u2019\u044b \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0442\u0441\u044f \u043f\u043e\u043b\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u043e\u0439 <code>\/tasks\/:taskId<\/code>, \u0430 \u043c\u043e\u0433\u0443\u0442 \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c\u0441\u044f \u0438\u0437 \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445:<\/p>\n<pre><code class=\"typescript\">const tasksPath = 'tasks'; const { taskId } = useParams() generateUrl(`${tasksPath}\/:taskid, { taskId }`)<\/code><\/pre>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u043f\u0440\u0438 \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u0435 \u043c\u043e\u0436\u043d\u043e \u0447\u0442\u043e-\u0442\u043e \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c. \u0412 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u043f\u043e\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0431\u0438\u0442\u044b\u0435 \u0441\u0441\u044b\u043b\u043a\u0438 \u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u043d\u0435\u0433\u043e\u0434\u0443\u044e\u0442.<\/p>\n<h3>\u041a \u0447\u0435\u043c\u0443 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u0440\u0438\u0439\u0442\u0438<\/h3>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u0435 \u043c\u044b \u043d\u0430\u0443\u0447\u0438\u043c\u0441\u044f \u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u044b\u0435 TypeScript \u0442\u0438\u043f\u044b \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0446\u0435\u043d\u0442\u0440\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0440\u043e\u0443\u0442\u0438\u043d\u0433\u0430.<\/p>\n<p>\u0412 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 TypeScript-first routing \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <a href=\"https:\/\/type-route.zilch.dev\/\" rel=\"noopener noreferrer nofollow\">type-route<\/a>, \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u0438\u0441\u0430\u0442\u044c \u0441 \u043d\u0443\u043b\u044f. \u041a \u0442\u043e\u043c\u0443 \u0436\u0435 \u043d\u0430\u0448\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u043e \u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u043b\u044e\u0431\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 \u0440\u043e\u0443\u0442\u0438\u043d\u0433\u0430.<\/p>\n<h4>\u0427\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0432 \u0438\u0442\u043e\u0433\u0435<\/h4>\n<figure class=\"full-width\">\n<div><figcaption>\u0418\u0442\u043e\u0433\u043e\u0432\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0440\u043e\u0443\u0442\u0438\u043d\u0433\u0430<\/figcaption><\/div>\n<\/figure>\n<figure class=\"full-width\">\n<div><figcaption>\u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u0438 \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f<\/figcaption><\/div>\n<\/figure>\n<ul>\n<li>\n<p>\u0414\u0435\u0440\u0435\u0432\u043e \u0432\u0441\u0435\u0445 \u0440\u043e\u0443\u0442\u043e\u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432&nbsp;\u043e\u0434\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435&nbsp;\u2014 json \u043a\u043e\u043d\u0444\u0438\u0433;<\/p>\n<\/li>\n<li>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u044d\u0442\u0438 \u0440\u043e\u0443\u0442\u044b \u0438 \u0432\u0438\u0434\u0435\u0442\u044c \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0438 \u0432&nbsp;IDE;<\/p>\n<\/li>\n<li>\n<p>\u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044e \u0438\u0442\u043e\u0433\u043e\u0432\u043e\u0433\u043e URL \u043f\u043e&nbsp;path\u00bb\u0443;<\/p>\n<\/li>\n<li>\n<p>\u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043f\u0440\u0438&nbsp;\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 URL.<\/p>\n<\/li>\n<\/ul>\n<h3>\u0418\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b<\/h3>\n<p>\u0427\u0442\u043e&nbsp;\u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043c\u0438\u043c\u043e \u0441\u0430\u043c\u043e\u0433\u043e TS<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/react.dev\/\" rel=\"noopener noreferrer nofollow\">react<\/a>&nbsp;\u2014 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433\u0430;<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/sindresorhus\/type-fest\" rel=\"noopener noreferrer nofollow\">type\u2011fest<\/a>&nbsp;\u2014 \u043d\u0430\u0431\u043e\u0440 ts \u0443\u0442\u0438\u043b\u0438\u0442;<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/www.npmjs.com\/package\/expect-type\" rel=\"noopener noreferrer nofollow\">expect\u2011type<\/a>&nbsp;\u2014 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0438\u043f\u043e\u0432;<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/reactrouter.com\/en\/main\" rel=\"noopener noreferrer nofollow\">react\u2011router<\/a>&nbsp;\u2014 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0440\u043e\u0443\u0442\u0438\u043d\u0433\u0430 \u0434\u043b\u044f&nbsp;React.<\/p>\n<\/li>\n<\/ul>\n<h3>\u0418\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0438\u0437 path<\/h3>\n<p>\u0412 <a href=\"https:\/\/reactrouter.com\/en\/main\" rel=\"noopener noreferrer nofollow\">react-router<\/a> \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u0442\u0438\u043f\u044b \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438, \u043d\u043e \u043c\u044b \u043a\u043e\u043d\u0435\u0447\u043d\u043e-\u0436\u0435 \u0438\u0437\u043e\u0431\u0440\u0435\u0442\u0435\u043c \u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434.<br \/>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0442\u0438\u043f\u044b:<\/p>\n<pre><code class=\"typescript\">export type ExtractParams&lt;Path&gt; = Path extends `${infer Segment}\/${infer Rest}`   ? ExtractParam&lt;Segment&gt; &amp; ExtractParams&lt;Rest&gt;   : ExtractParam&lt;Path&gt;  \/\/ \u041f\u0440\u0438\u043c\u0435\u0440  type Params = ExtractParams&lt;'\/tasks\/:taskId\/:commentId'&gt;  \/\/ Params = { taskId: string; commentId: string; }  export type ExtractParam&lt;Segment&gt; = Segment extends `:${infer Param}`   ? {     [Param]: string;   }   : unknown;  \/\/ \u041f\u0440\u0438\u043c\u0435\u0440 type Param = ExtractParam&lt;':taskId'&gt; \/\/ Param = { taskId: string; }<\/code><\/pre>\n<p>\u042d\u0442\u0438 \u0434\u0432\u0430 \u0442\u0438\u043f\u0430&nbsp;\u2014 \u043e\u0441\u043d\u043e\u0432\u0430 \u0434\u043b\u044f&nbsp;\u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0438 IDE suggestions \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043f\u0440\u0438&nbsp;\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 URL \u043d\u0430&nbsp;\u043e\u0441\u043d\u043e\u0432\u0435 path:<\/p>\n<figure class=\"full-width\">\n<div><figcaption>\u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f<\/figcaption><\/div>\n<\/figure>\n<figure class=\"full-width\">\n<div><figcaption>IDE-suggestions<\/figcaption><\/div>\n<\/figure>\n<h4>ExtractParam<\/h4>\n<p>\u041d\u0430\u043f\u043e\u043c\u043d\u044e, \u0447\u0442\u043e&nbsp;path&nbsp;\u2014 \u044d\u0442\u043e \u0441\u0442\u0440\u043e\u043a\u0430 <code>\/segment\/:parameterSegment\/segement2<\/code> \u043f\u043e&nbsp;\u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0438\u0442\u043e\u0433\u043e\u0432\u044b\u0439 URL. \u0421\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437&nbsp;\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u043e\u0432:<\/p>\n<ul>\n<li>\n<p><code>:parameterSegment<\/code>&nbsp;\u2014 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043d\u0430&nbsp;\u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432&nbsp;URL;<\/p>\n<\/li>\n<li>\n<p><code>segment<\/code>&nbsp;\u2014 \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u0430\u044f \u0447\u0430\u0441\u0442\u044c;<\/p>\n<\/li>\n<li>\n<p><code>\/<\/code>&nbsp;\u2014 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u044e\u0449\u0438\u0439 \u0441\u043b\u0435\u0448.<\/p>\n<\/li>\n<\/ul>\n<p>\u0420\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u043f\u0435\u0440\u0432\u044b\u0439 \u0442\u0438\u043f <code>ExtractParam<\/code>. \u041e\u043d \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0430 \u0441&nbsp;\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c \u0432 <code>object type<\/code> \u0441&nbsp;\u0442\u0430\u043a\u0438\u043c&nbsp;\u0436\u0435 \u043a\u043b\u044e\u0447\u043e\u043c<\/p>\n<pre><code class=\"typescript\">export type ExtractParam&lt;Path&gt; = Path extends `:${infer Param}`   ? {     [Param]: string;   }   : {};  \/\/ expectTypeOf - \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 expect-type \/\/ @ts-expect-error - \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439 \u0438\u0437 expect-type \u043d\u0430\u043f\u043e\u0434\u043e\u0431\u0438\u0438 eslint-disable-next-line it('ExtractParam type ', () =&gt; {   \/\/ { taskId: string }    expectTypeOf({ taskId: '' })     .toMatchTypeOf&lt;ExtractParam&lt;':taskId'&gt;&gt;();      \/\/ { commentId: string }    expectTypeOf({ commentId: '' })     .toMatchTypeOf&lt;ExtractParam&lt;':commentId'&gt;&gt;();      \/\/ {} \u0432\u0442\u043e\u0440\u0430\u044f \u0432\u0435\u0442\u043a\u0430 conditional   expectTypeOf({ }).toMatchTypeOf&lt;ExtractParam&lt;'somestring'&gt;&gt;();       \/\/ @ts-expect-error    \/\/ !== { taskId: number }     expectTypeOf({ taskId: 1 }).toMatchTypeOf&lt;ExtractParam&lt;':taskId'&gt;&gt;();      \/\/ @ts-expect-error    \/\/ !== { }   expectTypeOf({ }).toEqualTypeOf&lt;ExtractParam&lt;':taskId'&gt;&gt;(); });<\/code><\/pre>\n<p>\u0414\u043b\u044f&nbsp;\u043e\u0431\u043b\u0435\u0433\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0435\u0440\u0435\u0432\u0435\u0434\u0435\u043c \u0442\u0438\u043f <code>ExtractParam<\/code> \u0432&nbsp;\u043f\u0441\u0435\u0432\u0434\u043e\u043a\u043e\u0434 \u043d\u0430&nbsp;JS.<\/p>\n<p><em>(* \u042f \u043d\u0435&nbsp;\u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u044e, \u0447\u0442\u043e&nbsp;\u043f\u043e\u0434&nbsp;\u043a\u0430\u043f\u043e\u0442\u043e\u043c \u043e\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a)<br \/>(** \u0414\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u044f \u043f\u043e\u0437\u0430\u0438\u043c\u0441\u0442\u0432\u043e\u0432\u0430\u043b \u0438\u0437&nbsp;\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <\/em><a href=\"https:\/\/github.com\/mistlog\/typetype\" rel=\"noopener noreferrer nofollow\"><em>type\u2011type<\/em><\/a><em>, \u043e\u043d\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u0432&nbsp;JS\u2011like \u043d\u043e\u0442\u0430\u0446\u0438\u0438)<\/em><\/p>\n<pre><code class=\"typescript\">export const extractParam = (path: any) =&gt; {   if (typeof path === \"string\" &amp;&amp; path.startsWith(':')) {    const param = path.slice(1);     return {     [param]: '',    }   }   else {     return {}   } }  it('extractParam func', function () {   expect(extractParam(':taskId')).toEqual({ taskId: '' });   expect(extractParam('taskId')).toEqual({ }); });<\/code><\/pre>\n<p>\u0412&nbsp;\u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u044b \u0432\u0441\u0435\u043c \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u043c \u0441\u043b\u043e\u0432\u0430\u043c \u0438 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044f\u043c:<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th data-colwidth=\"213\" width=\"213\">\n<p>\u041a\u043e\u043d\u0446\u0435\u043f\u0442<\/p>\n<\/th>\n<th data-colwidth=\"262\" width=\"262\">\n<p>TS<\/p>\n<\/th>\n<th>\n<p>JS<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td data-colwidth=\"213\" width=\"213\">\n<p align=\"left\"><strong>Property mapping<\/strong><\/p>\n<\/td>\n<td data-colwidth=\"262\" width=\"262\">\n<p align=\"left\"><code>{<br \/> [Param]: string;<br \/>}<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>{   <br \/>  [param]: ''<br \/>}<\/code><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"213\" width=\"213\">\n<p align=\"left\"><a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/2\/generics.html\" rel=\"noopener noreferrer nofollow\"><strong>GENERICS<\/strong><\/a><strong><br \/><\/strong>\u041e\u0431\u043e\u0431\u0449\u0435\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u044b &#8212; \u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0438\u0435 \u043d\u0430 \u0432\u0445\u043e\u0434 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440<\/p>\n<\/td>\n<td data-colwidth=\"262\" width=\"262\">\n<p align=\"left\"><code>type ExtractParam&lt;Path&gt;<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>const extractParam = (path: any)<\/code><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"213\" width=\"213\">\n<p align=\"left\"><a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/2\/generics.html#generic-constraints\" rel=\"noopener noreferrer nofollow\"><strong>GENERICS CONSTRAINTS<\/strong><\/a><strong><br \/><\/strong>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u043e\u0431\u044b\u0447\u043d\u044b\u043c \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u043c, \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0430 \u0442\u043e \u0447\u0442\u043e \u0432\u0445\u043e\u0434\u043d\u043e\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0438\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0443 \u0441\u0442\u0440\u043e\u043a<\/p>\n<\/td>\n<td data-colwidth=\"262\" width=\"262\">\n<p align=\"left\"><code>if (typeof path === \"string\" &amp;&amp; path.startsWith(':'))<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>Path extends ':${infer Param}'<\/code><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"213\" width=\"213\">\n<p align=\"left\"><a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/2\/conditional-types.html\" rel=\"noopener noreferrer nofollow\"><strong><em>CONDITIONAL TYPES<\/em><\/strong><\/a><strong><br \/><\/strong>\u0423\u0441\u043b\u043e\u0432\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u043e\u0431\u044b\u0447\u043d\u043e\u043c\u0443 if-else \u0431\u043b\u043e\u043a\u0443, \u043b\u0438\u0431\u043e \u0442\u0435\u0440\u043d\u0430\u0440\u043d\u043e\u043c\u0443 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0443<\/p>\n<\/td>\n<td data-colwidth=\"262\" width=\"262\">\n<p align=\"left\"><code>Path extends ':${infer Param}'<br \/> ? {<br \/> [Param]: string;<br \/> }<br \/> : {};<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>if (condition) { <br \/>}<br \/>else {<br \/> return {}<br \/>}<br \/><\/code> <\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"213\" width=\"213\">\n<p align=\"left\"><a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/release-notes\/typescript-2-8.html#type-inference-in-conditional-types\" rel=\"noopener noreferrer nofollow\"><strong>INFER<\/strong><\/a><br \/> \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044e \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043f\u043e\u0441\u043b\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u0430 <code>:<\/code><br \/>* \u041c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432 generic constraints<br \/> <em>** \u0415\u0441\u043b\u0438 TS \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0442\u0438\u043f \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0441\u043b\u0435 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430, \u0442\u043e \u043e\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 unknown<\/em><\/p>\n<\/td>\n<td data-colwidth=\"262\" width=\"262\">\n<p align=\"left\"><code>Path extends ':${infer Param}'<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>const param = path.slice(1);<\/code><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h4>ExtractParams<\/h4>\n<p>\u0422\u0438\u043f <code>ExtractParams<\/code> \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 path \u0432&nbsp;\u043e\u0431\u044a\u0435\u043a\u0442 \u0433\u0434\u0435 \u043a\u043b\u044e\u0447\u0438 \u044d\u0442\u043e \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u044b \u0441&nbsp;\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438, \u0430&nbsp;\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0442\u0438\u043f <code>string<\/code><\/p>\n<pre><code class=\"typescript\">export type ExtractParams&lt;Path&gt; = Path extends `${infer Segment}\/${infer Rest}`   ? ExtractParam&lt;Segment&gt; &amp; ExtractParams&lt;Rest&gt;    : ExtractParam&lt;Path&gt;  it('ExtractParams', () =&gt; {   \/\/ { taskId: string; }   expectTypeOf({ taskId: '' })   .toMatchTypeOf&lt;ExtractParams&lt;'\/:taskId'&gt;&gt;();        \/\/ \u0420\u0435\u043a\u0443\u0440\u0441\u0438\u044f ( {} &amp; { taskId: string } &amp; { tab: string } )   \/\/ { taskId: string; tab: string; }   expectTypeOf({ taskId: '', tab: '' })     .toMatchTypeOf&lt;ExtractParams&lt;'\/tasks\/:taskId\/:tab'&gt;&gt;();      \/\/ \u0420\u0435\u043a\u0443\u0440\u0441\u0438\u044f ( {} &amp; {} &amp; {} )   \/\/ { }    expectTypeOf({ }).toEqualTypeOf&lt;ExtractParams&lt;'\/path\/without\/params'&gt;&gt;();   \/\/ @ts-expect-error   \/\/ { taskId: number; }   expectTypeOf({ taskId: 1 }).toMatchTypeOf&lt;ExtractParams&lt;'\/:taskId'&gt;&gt;(); }) <\/code><\/pre>\n<pre><code class=\"typescript\">export const extractParams = (path: string): Record&lt;string, string&gt; =&gt; {   const firstSlash = path.indexOf('\/');   \/\/ \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u043f\u0440\u0435\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0438   if (firstSlash === -1) {     return extractParam(path);   }   \/\/ \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u043c \u043f\u0435\u0440\u0432\u044b\u0439 \u0441\u0435\u0433\u043c\u0435\u043d\u0442 \u0438 \u043e\u0441\u0442\u0430\u0432\u0448\u0443\u044e\u0442\u0441\u044f \u0441\u0442\u0440\u043e\u043a\u0443   \/\/ \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 [segment, rest] = ['tasks', ':taskId']   const [segment, rest] = [path.slice(0, firstSlash), path.slice(firstSlash + 1)];   return {     ...extractParam(segment),     \/\/ \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432      ...extractParams(rest)   } }  it('extractParams func', function () {   expect(extractParams('\/:taskId')).toEqual({ taskId: '' });   expect(extractParams('\/tasks\/:taskId\/:tab')).toEqual({ taskId: '', tab: '' });   expect(extractParams('\/path\/without\/params')).toEqual({ }); });<\/code><\/pre>\n<p>\u0417\u0430\u043c\u0435\u0442\u0438\u043c, \u0447\u0442\u043e&nbsp;\u0437\u0434\u0435\u0441\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f <a href=\"https:\/\/www.typescriptlang.org\/play#example\/recursive-type-references\" rel=\"noopener noreferrer nofollow\"><strong>Recursive types<\/strong><\/a> . \u0415\u0441\u043b\u0438 \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u0442\u044c \u043a\u0430\u043a&nbsp;\u0443\u0441\u0442\u0440\u043e\u0435\u043d\u044b \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<ul>\n<li>\n<p>\u041e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/p>\n<\/li>\n<li>\n<p>\u0423\u0441\u043b\u043e\u0432\u0438\u0435 \u043f\u0440\u0435\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0438<\/p>\n<\/li>\n<li>\n<p>\u0420\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432<\/p>\n<\/li>\n<\/ul>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th data-colwidth=\"148\" width=\"148\">\n<p>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435<\/p>\n<\/th>\n<th data-colwidth=\"286\" width=\"286\">\n<p>TS<\/p>\n<\/th>\n<th>\n<p>JS<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td data-colwidth=\"148\" width=\"148\">\n<p align=\"left\">\u041e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435<\/p>\n<\/td>\n<td data-colwidth=\"286\" width=\"286\">\n<p align=\"left\"><code>type ExtractParams&lt;Path&gt;<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>const extractParams<\/code><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"148\" width=\"148\">\n<p align=\"left\">\u0423\u0441\u043b\u043e\u0432\u0438\u0435 \u043f\u0440\u0435\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0438<\/p>\n<\/td>\n<td data-colwidth=\"286\" width=\"286\">\n<p align=\"left\"><code>Path extends \u2018${infer Segment}\/${infer Rest}\u2019<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>const firstSlash = path.indexOf('\/');<br \/> if (firstSlash === -1) {<br \/>   return extractParam(path);<br \/> }<\/code><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"148\" width=\"148\">\n<p align=\"left\">\u0420\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432<\/p>\n<\/td>\n<td data-colwidth=\"286\" width=\"286\">\n<p align=\"left\"><code>ExtractParam&lt;Segment&gt; &amp; ExtractParams&lt;Rest&gt;<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>{<br \/> ...extractParam(segment),<br \/> ...extractParams(rest)<br \/> }<\/code><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h3>\u041a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438<\/h3>\n<figure class=\"full-width\">\n<div><figcaption>\u0424\u043e\u0440\u043c\u0430\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f<\/figcaption><\/div>\n<\/figure>\n<p>\u0412&nbsp;react\u2011router \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f&nbsp;\u0434\u0435\u0440\u0435\u0432\u0430 \u0440\u043e\u0443\u0442\u0438\u043d\u0433\u0430 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 json \u043e\u0431\u044a\u0435\u043a\u0442.<\/p>\n<p>\u0414\u043b\u044f&nbsp;\u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0434\u0435\u0440\u0435\u0432\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043c\u0430\u0441\u0441\u0438\u0432 children.<\/p>\n<p>\u041d\u043e&nbsp;\u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0432&nbsp;\u0442\u043e\u043c, \u0447\u0442\u043e&nbsp;\u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043f\u043e&nbsp;\u0438\u043d\u0434\u0435\u043a\u0441\u0443 <code>children[0].fullPath<\/code>&nbsp;\u2014 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c.<\/p>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432\u044b children \u0432&nbsp;\u0434\u0435\u0440\u0435\u0432\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u043e\u043b\u043d\u044b\u0439 \u043f\u0443\u0442\u044c \u0434\u043e&nbsp;\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430:<\/p>\n<figure class=\"full-width\">\n<div><figcaption>\u0421\u0445\u0435\u043c\u0430 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f JS \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432<\/figcaption><\/div>\n<\/figure>\n<p><strong>\u0414\u0430\u043d\u043e:<\/strong><\/p>\n<ul>\n<li>\n<p>\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438<\/p>\n<\/li>\n<\/ul>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p><\/code><\/p>\n<\/td>\n<p><\/br><\/code><\/p>\n<\/td>\n<\/td>\n<\/tr>\n<\/tr>\n<\/tr>\n<\/td>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-347585","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/347585","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=347585"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/347585\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=347585"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=347585"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=347585"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}