Giter Site home page Giter Site logo

paidaxing-web / you-don-t-know-ts Goto Github PK

View Code? Open in Web Editor NEW
39.0 2.0 9.0 69.22 MB

🔥🔥🔥 这是一个专注研究Typescript的网站,🎖🎖🎖在这里你可以全面深入学习Typescript相关知识,通过动画方式讲解TS,还有很多常见问题解答。你还可以挑战相应的题目,快来学习吧。

Home Page: https://youjia.sx.cn/you-dont-know-ts

TypeScript 10.87% Shell 0.03% Vue 9.19% JavaScript 64.30% CSS 9.33% HTML 6.29%
ts typescript typescript-library animation conditional-types generics mapped-types union-types utility-types typescript-interface

you-don-t-know-ts's Issues

1.2.实现Pick

type MyPick<T, K extends keyof T> ={
[P in K]:T[P]
};

2-2实现-omit.md

//你的答案
type MyOmit<T, K> = { [P in keyof T as P extends K ? never : P]: T[P] };

1.3.实现Awaited

/* _____________ 你的代码 _____________ */

type MyAwaited<T> = T extends Promise<infer U>
  ? MyAwaited<U>
  : T extends { then: (p: (arg: infer K) => any) => any }
  ? K
  : T;

/* _____________ 测试用例 _____________ */
import type { Equal, Expect } from '@type-challenges/utils';

type X = Promise<string>;
type Y = Promise<{ field: number }>;
type Z = Promise<Promise<string | number>>;
type Z1 = Promise<Promise<Promise<string | boolean>>>;
type T = { then: (onfulfilled: (arg: number) => any) => any };

type cases = [
  Expect<Equal<MyAwaited<X>, string>>,
  Expect<Equal<MyAwaited<Y>, { field: number }>>,
  Expect<Equal<MyAwaited<Z>, string | number>>,
  Expect<Equal<MyAwaited<Z1>, string | boolean>>,
  Expect<Equal<MyAwaited<T>, number>>
];

// @ts-expect-error
type error = MyAwaited<number>;

1.2.实现Pick

type MyPick<T, K extends keyof T> = {

  [P in K]:T[P]
};

2-3-实现Readonly2.md

type MyReadonly2<T, K extends keyof T = keyof T> = Omit<T, K> & Readonly<T>;
//你的答案

2-2实现-omit.md

//你的答案
type MyOmit<T, K> = { [P in keyof T as P extends K ? never : P]: T[P] };

1.1.hello-world

// 你的答案
import './style.css';
import type { Equal, Expect, NotAny } from '@type-challenges/utils';
// Write TypeScript code!
const appDiv: HTMLElement = document.getElementById('app');
appDiv.innerHTML = `<h1>第一题:Hello World</h1><p> 你需要使得14行不会抛出异常</p>`;

// 期望是一个 string 类型
type HelloWorld = string;
//你需要使得如下这行不会抛出异常
type cases = [Expect<NotAny<HelloWorld>>, Expect<Equal<HelloWorld, string>>];

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.