随笔分类 -  TypeScript

上一页 1 ··· 18 19 20 21 22 23 24 25 26 ··· 30 下一页
摘要:Res1: https://www.typescript-training.com/course/making-typescript-stick/08-type-challenges/#returnoff Res2: https://learntypescript.dev/09/l2-conditi 阅读全文
posted @ 2022-07-19 16:24 Zhentiw 阅读(201) 评论(0) 推荐(0)
摘要:`any` type, you can assign any value for any type. For `unkown`, you can also assign any value to unkwon: But you cannot assign unkwon variable to ano 阅读全文
posted @ 2022-07-19 02:27 Zhentiw 阅读(33) 评论(0) 推荐(0)
摘要:const $: any = {} /** * Get the <button> element with the class 'continue' * and change its HTML to 'Next Step...' */ $("button.continue").html("Next 阅读全文
posted @ 2022-07-15 15:56 Zhentiw 阅读(38) 评论(0) 推荐(0)
摘要:Refer: https://www.cnblogs.com/Answer1215/p/15084496.html A string is a primitive value, and all primitive values are immutable. Q1: const a = "Fronte 阅读全文
posted @ 2022-07-13 18:53 Zhentiw 阅读(227) 评论(0) 推荐(0)
摘要:Given this code as starter: export interface DataEntity { id: string } export interface Movie extends DataEntity { director: string } export interface 阅读全文
posted @ 2022-07-13 18:52 Zhentiw 阅读(36) 评论(0) 推荐(0)
摘要:Problem when typing Dictionaries: type Dict<T> = { [K: string]: T } const d: Dict<string[]> = {} d.rhubarb.join(", ") // 💥 Even `d.rhubarb` is undefi 阅读全文
posted @ 2022-07-13 17:57 Zhentiw 阅读(31) 评论(0) 推荐(0)
摘要:Since TypeScript v4.2, we can do remapping by using `as` keyword type Colors = "red" | "green" | "blue" type ColorSelector = { [K in Colors as `select 阅读全文
posted @ 2022-07-13 17:48 Zhentiw 阅读(36) 评论(0) 推荐(0)
摘要:type Statistics = { [K in `${"median" | "mean"}Value`]?: number } Mappiing a sub type: // let winFns: "setInterval" | "setTimeout" type winFns = Extra 阅读全文
posted @ 2022-07-12 14:53 Zhentiw 阅读(37) 评论(0) 推荐(0)
摘要:Main idea is enforce you to do type checking in catch block, because if you want to get Error stacktrace, the throw value should be an Error type, if 阅读全文
posted @ 2022-07-12 14:09 Zhentiw 阅读(28) 评论(0) 推荐(0)
摘要:This major convenience feature reduces the need for class field type annotations by inferring their types from assignments in the constructor. It’s im 阅读全文
posted @ 2022-07-12 14:04 Zhentiw 阅读(32) 评论(0) 推荐(0)
摘要:https://www.typescript-training.com/course/making-typescript-stick/03-recent-updates-to-typescript/#variadic-tuple-types Before V4, for type, it is po 阅读全文
posted @ 2022-07-11 16:03 Zhentiw 阅读(41) 评论(0) 推荐(0)
摘要:export interface TwitterResolverContext { db: Db; dbTweetCache: Record<string, DbTweet>; dbUserCache: Record<string, DbUser>; dbTweetToFavoriteCountMa 阅读全文
posted @ 2022-07-08 15:56 Zhentiw 阅读(33) 评论(0) 推荐(0)
摘要:https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-5.html post.server.ts: export type Post = { slug: string; title: string; }; ex 阅读全文
posted @ 2022-06-23 14:32 Zhentiw 阅读(297) 评论(0) 推荐(0)
摘要:export function assertType<T>(obj: unknown = {}): T { return obj as T } const store = assertType<Store>({select: () => of()}) 阅读全文
posted @ 2022-05-09 14:34 Zhentiw 阅读(46) 评论(0) 推荐(0)
摘要:export type Letter = 'a' | 'b' | 'c' type RemoveC<TType> = TType extends 'c' ? never: TType; type WithoutC = RemoveC<Letter>; 阅读全文
posted @ 2022-04-25 14:48 Zhentiw 阅读(37) 评论(0) 推荐(0)
摘要:class SDK { constructor(public loggedInUserId?: string) {} createPost(title: string) { this.assertUserIsLoggedIn(); createPost(this.loggedInUserId, ti 阅读全文
posted @ 2022-04-25 14:42 Zhentiw 阅读(49) 评论(0) 推荐(0)
摘要:Config store app/store.ts import { configureStore } from "@reduxjs/toolkit"; export const store = configureStore({ reducer: {} }); main.tsx import Rea 阅读全文
posted @ 2022-04-23 17:59 Zhentiw 阅读(313) 评论(0) 推荐(0)
摘要:Let's see when we have following code: interface Animal { name: string; } interface Human { firstName: string; lastName: string; } const getDisplayNam 阅读全文
posted @ 2022-04-22 20:30 Zhentiw 阅读(41) 评论(0) 推荐(0)
摘要:type Twitter = { tweets: number} type Instagram = {canFollow: boolean} function describeAccount(account: Twitter | Instagram) { if (account.tweets) { 阅读全文
posted @ 2022-03-30 15:26 Zhentiw 阅读(48) 评论(0) 推荐(0)
摘要:import { json } from "remix"; import path from "path"; import fs from "fs/promises"; import parseFrontMatter from "front-matter"; import invariant fro 阅读全文
posted @ 2022-03-26 01:45 Zhentiw 阅读(110) 评论(0) 推荐(0)

上一页 1 ··· 18 19 20 21 22 23 24 25 26 ··· 30 下一页