首页 > 其他分享 >TypeScript function arguments destructuring All In One

TypeScript function arguments destructuring All In One

时间:2022-08-15 19:12:19浏览次数:88  
标签:function TypeScript destructuring log serverUrl repo context owner

TypeScript function arguments destructuring All In One


const log = console.log;

const context = {
  repo: {
    repo: "cdn",
    owner: "xgqfrms",
  },
  serverUrl: "https://github.com/",
};

type GithubContext = typeof context;

function getRepoUrl(context: GithubContext): string {
  const { repo, serverUrl } = context;
  log(`context =`, context);
  log(`repo, serverUrl =`, repo, serverUrl);
  return `${serverUrl}/${repo.owner}/${repo.repo}`;
}

getRepoUrl(context);

// function 参数解构 ✅
function getRepoUrl2({ repo, serverUrl }: GithubContext): string {
  log(`\n repo, serverUrl =`, repo, serverUrl);
  return `${serverUrl}/${repo.owner}/${repo.repo}`;
}

getRepoUrl2(context);

"use strict";
const log = console.log;
const context = {
    repo: {
        repo: "cdn",
        owner: "xgqfrms",
    },
    serverUrl: "https://github.com/",
};
function getRepoUrl(context) {
    const { repo, serverUrl } = context;
    log(`context =`, context);
    log(`repo, serverUrl =`, repo, serverUrl);
    return `${serverUrl}/${repo.owner}/${repo.repo}`;
}
getRepoUrl(context);
// function 参数解构 ✅
function getRepoUrl2({ repo, serverUrl }) {
    log(`\n repo, serverUrl =`, repo, serverUrl);
    return `${serverUrl}/${repo.owner}/${repo.repo}`;
}
getRepoUrl2(context);

refs

https://www.typescriptlang.org/play?


Flag Counter

©xgqfrms 2012-2020

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载

标签:function,TypeScript,destructuring,log,serverUrl,repo,context,owner
From: https://www.cnblogs.com/xgqfrms/p/16589079.html

相关文章