随笔分类 - TypeScript
摘要:When you try to import image in typescript project, it will report issue import logo from "./assets/react.svg" What you can do is, create a types.d.ts
阅读全文
摘要:整合 TypeScript 准备工作 首先我们需要有一个基于 ts 的项目。 第一步通过 npm init -y 初始化项目 接下来通过: npm install typescript 局部安装 typescript。 之后还需要生成 typescript 的配置文件,通过命令: npx tsc -
阅读全文
摘要:The Input is Different than the Output We've reached the point with Zod where our input is different than our output. In other words, you can generate
阅读全文
摘要:Define a component with props and defualt props value <script setup lang="ts"> import { ref, onMounted } from 'vue' import fetchCount from '../service
阅读全文
摘要:<template> <router-link class="event-link" :to="{ name: 'EventDetails', params: { id: event.id } }" > <div class="event-card"> <span>@{{ event.time }}
阅读全文
摘要:/** * Utility for extracting the parameters from a function overload (for typed emits) * https://github.com/microsoft/TypeScript/issues/32164#issuecom
阅读全文
摘要:We have a module: const key = Symbol('key') export class A { [key] = 1 value () { console.log(this[key]) } } It seems that keyis not expose to outside
阅读全文
摘要:const BookingSchema = z.object({ roomType: z.string(), dueDate: z .string({ message: "invalid due date", }) .date('date format is wrong'), numberOfGue
阅读全文
摘要:export enum EffectFlags { /** * ReactiveEffect only */ ACTIVE = 1 << 0, RUNNING = 1 << 1, TRACKING = 1 << 2, NOTIFIED = 1 << 3, DIRTY = 1 << 4, ALLOW_
阅读全文
摘要:type BanType<T, E> = T extends E ? never : T; type BanDate<T> = BanType<T, Date>; function log<T>(x: BanDate<T>) { console.log() } log(new Date()) //
阅读全文
摘要:const requestFullscreenProps = [ "requestFullScreen", "webkitRequestFullScreen", "mozRequestFullScreen", "msRequestFullScreen", ] as const; const exit
阅读全文
摘要:Consider this Result type: type Result<TResult, TError> = | { success: true; data: TResult; } | { success: false; error: TError; }; The Result type ha
阅读全文
摘要:Consider this package.json file: { "name": "exercise", "version": "1.0.0", "main": "index.js", "scripts": { "dev": "run-p dev:*", "dev:client": "tsc -
阅读全文
摘要: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
阅读全文
摘要:export const randomColor = () => { return "#" + Math.random().toString(16).substring(2, 8).padEnd(6, '0') } export const randomString = (len: number)
阅读全文
摘要:The solution is to modify the tsconfig.json file to enable declarationMap under the compilerOptions. // inside tsconfig.json { "compilerOptions": { "d
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要:The module and moduleResolution options in the tsconfig.json file can be confusing. Here we'll discuss the differences between the module and moduleRe
阅读全文
摘要:Here we're attempting to import several PNG files into our TypeScript program: import pngUrl1 from "./example1.png"; // red squiggly line under "./exa
阅读全文