随笔分类 -  TypeScript

上一页 1 2 3 4 5 6 ··· 30 下一页
摘要:const requestFullscreenProps = [ "requestFullScreen", "webkitRequestFullScreen", "mozRequestFullScreen", "msRequestFullScreen", ] as const; const exit 阅读全文
posted @ 2024-09-09 14:39 Zhentiw 阅读(19) 评论(0) 推荐(0)
摘要:Consider this Result type: type Result<TResult, TError> = | { success: true; data: TResult; } | { success: false; error: TError; }; The Result type ha 阅读全文
posted @ 2024-09-06 15:03 Zhentiw 阅读(16) 评论(0) 推荐(0)
摘要:Consider this package.json file: { "name": "exercise", "version": "1.0.0", "main": "index.js", "scripts": { "dev": "run-p dev:*", "dev:client": "tsc - 阅读全文
posted @ 2024-09-04 14:41 Zhentiw 阅读(24) 评论(0) 推荐(0)
摘要:A long-awaited feature is smart incremental builds for TypeScript projects. In 3.0 you can use the --build flag with tsc. This is effectively a new en 阅读全文
posted @ 2024-09-03 21:28 Zhentiw 阅读(66) 评论(0) 推荐(0)
摘要:export const randomColor = () => { return "#" + Math.random().toString(16).substring(2, 8).padEnd(6, '0') } export const randomString = (len: number) 阅读全文
posted @ 2024-09-03 20:35 Zhentiw 阅读(17) 评论(0) 推荐(0)
摘要:The solution is to modify the tsconfig.json file to enable declarationMap under the compilerOptions. // inside tsconfig.json { "compilerOptions": { "d 阅读全文
posted @ 2024-09-02 20:41 Zhentiw 阅读(17) 评论(0) 推荐(0)
摘要:One of the interesting things about verbatimModuleSyntax in TypeScript is that it requires a specific type of import when you're working with types. L 阅读全文
posted @ 2024-08-13 01:29 Zhentiw 阅读(166) 评论(0) 推荐(0)
摘要:To fix the CommonJS export issue, we need to make a change to our tsconfig.json file. Add the verbatimModuleSyntax setting and set it to true: { "comp 阅读全文
posted @ 2024-08-13 01:24 Zhentiw 阅读(235) 评论(0) 推荐(0)
摘要:The module and moduleResolution options in the tsconfig.json file can be confusing. Here we'll discuss the differences between the module and moduleRe 阅读全文
posted @ 2024-08-13 01:17 Zhentiw 阅读(128) 评论(0) 推荐(0)
摘要:Here we're attempting to import several PNG files into our TypeScript program: import pngUrl1 from "./example1.png"; // red squiggly line under "./exa 阅读全文
posted @ 2024-08-08 19:20 Zhentiw 阅读(20) 评论(0) 推荐(0)
摘要:Here we're importing a function myModuleFunc from my-module: import { myModuleFunc } from "my-module"; // red squiggly line under "my-module" Let's st 阅读全文
posted @ 2024-08-08 19:17 Zhentiw 阅读(23) 评论(0) 推荐(0)
摘要:In tsconfig file, you have targetand libsconfiguration. You always need to define a target, recommended as es2022 Specifying the lib option also lets 阅读全文
posted @ 2024-08-08 19:01 Zhentiw 阅读(21) 评论(0) 推荐(0)
摘要:The declare keyword in TypeScript allows you to specify types for global variables. Whenever you use it, an ambient context is created, which means th 阅读全文
posted @ 2024-08-07 19:13 Zhentiw 阅读(12) 评论(0) 推荐(0)
摘要:Typescript check a file whether it contains any export/import, if it is, then it's a module; if not then it's a script. What's the difference between  阅读全文
posted @ 2024-08-07 19:04 Zhentiw 阅读(13) 评论(0) 推荐(0)
摘要:/** * How do we annotate the errors this function throws? */ type PossibleErrors = SyntaxError | DOMException; const getUserFromLocalStorage = (id: st 阅读全文
posted @ 2024-08-07 18:58 Zhentiw 阅读(10) 评论(0) 推荐(0)
摘要:For the following code: const objOfFunctions = { string: (input: string) => input.toUpperCase(), number: (input: number) => input.toFixed(2), boolean: 阅读全文
posted @ 2024-08-07 17:53 Zhentiw 阅读(18) 评论(0) 推荐(0)
摘要:import { expect, it, vitest } from 'vitest'; const logId = (obj: { id: string }) => { console.log(obj.id); }; const logName = (obj: { name: string }) 阅读全文
posted @ 2024-08-06 19:56 Zhentiw 阅读(14) 评论(0) 推荐(0)
摘要:Make those pass: import { Equal, Expect } from "@total-typescript/helpers"; type Event = "click" | "hover" | "scroll"; type CallbackType = unknown; co 阅读全文
posted @ 2024-08-06 15:13 Zhentiw 阅读(28) 评论(0) 推荐(0)
摘要:function pipe<A, B>(fn: (a: A) => B) { function run(a: A) { return fn(a) } run.pipe = <C, >(fn2: (b: B) => C) => pipe((a: A) => fn2(fn(a))) return run 阅读全文
posted @ 2024-08-02 14:51 Zhentiw 阅读(19) 评论(0) 推荐(0)
摘要:type BaseTable = { [colName: string]: string | number | boolean; } type Columns<Tables extends { [tableName: string]: BaseTable }> = { [K in keyof Tab 阅读全文
posted @ 2024-08-02 14:50 Zhentiw 阅读(12) 评论(0) 推荐(0)

上一页 1 2 3 4 5 6 ··· 30 下一页