TypeScript 02:interface、type 与类型收窄

TypeScript报错“Type ‘null‘ is not assignable“?联合类型的窄化判断 TypeScript严格类型检查下"Type 'null' is not assignable"错误分析及解决策略。文章系统讲解了联合类型窄化判断的六大方案:1)显式联合类型声明,2)类型守卫函数,3)可选链操作符,4)空值合并运算符,5)非空断言操作符(慎用),6)泛型包装类型。通过API响应处理等实战案例,比较了各方案的安全性、性能及适用场景。最佳实践建议严格启用strictNullChecks,优先使用可选链和空值合并运算符,复杂场景采用类型守卫,并给出了编译器配置与性能优化建议。 阅读详情

TypeScript 02:interface、type 与类型收窄

1. interface:给对象形状起名字

第 1 课的 { name: string; age: number } 每次都要重抄一遍——起个名字就能复用:

interface User {
  name: string
  age: number
}

function greet(u: User) {
  return `你好,${u.name}`
}

greet({ name: 'Tom', age: 18 }) // ✅
greet({ name: 'Tom' }) // ❌ Property 'age' is missing in type 'User'

形状可以继承:

interface Vip extends User {
  level: number
}

const v: Vip = { name: 'Tom', age: 18, level: 3 }

2. type:另一种起名方式

type 也能给形状起名,还擅长做 interface 做不到的事——给联合、字面量起名:

type ID = string | number
type Status = 'loading' | 'success' | 'error'

let page: Status = 'loading'
page = 'loaded' // ❌ Type '"loaded"' is not assignable to type 'Status'(拼错立刻暴露)

怎么选:对象形状两者都能用,团队统一一种即可;联合类型、字面量类型只能用 type。

3. 可选属性 ?: 与只读 readonly

interface Profile {
  name: string
  email?: string // 可有可无,实际类型是 string | undefined
  readonly id: number // 只能读,不能改
}

const p: Profile = { name: 'Tom', id: 1 } // 不写 email 合法
p.id = 2 // ❌ Cannot assign to 'id' because it is a read-only property

可选属性的实际类型是 string | undefined,用之前要确认存在:

if (p.email) {
  sendTo(p.email) // 这里 TS 知道 email 一定是 string
}

4. 字面量类型与 as const

string 是「任意字符串」,'loading' 本身也是一个类型——值被锁死为这一个:

const ROUTES = {
  home: '/',
  about: '/about',
} as const // 每个字段锁成字面量类型 '/' 和 '/about',且全部只读

ROUTES.home = '/x' // ❌ Cannot assign to 'home' because it is a read-only property

5. 类型收窄:使用联合类型的前提

联合类型的值,不能直接用某一方的特有能力——必须先收窄:

function describe(id: string | number) {
  // ❌ id.toUpperCase():Property 'toUpperCase' does not exist on type 'string | number'

  if (typeof id === 'string') {
    return id.toUpperCase() // ✅ 这里 TS 知道是 string
  }
  return id.toFixed(2) // ✅ 这里 TS 知道是 number
}

三种常用收窄手段:

if (typeof x === 'string') {} // ① typeof:区分原始类型
if ('fly' in animal) {} // ② in:对象有没有这个字段
if (r.ok === true) {} // ③ 具体值比较(配合字面量类型)

③ 的经典形态是可辨识联合——后端接口最常见:

type ApiResult = { ok: true; data: string[] } | { ok: false; message: string }

function handle(r: ApiResult) {
  if (r.ok) {
    return r.data.length // 收窄到成功分支,才有 data
  }
  return r.message // 收窄到失败分支,才有 message
}

6. unknown:安全的 any

any 是「随便用」;unknown 是「类型未知,但用之前必须收窄」:

const input: unknown = JSON.parse(text)

input.toFixed(2) // ❌ 'input' is of type 'unknown'

if (typeof input === 'number') {
  input.toFixed(2) // ✅ 收窄后才能用
}

外部数据(接口返回、JSON)优先按 unknown 处理,逼自己先判断再用。

7. 高频报错速查

报错人话
Property 'x' does not exist on type 'string | number'联合类型没收窄就想用单方方法
'input' is of type 'unknown'unknown 必须先收窄再使用
Cannot assign to 'id' because it is a read-only property给 readonly 赋值了
Type '"loaded"' is not assignable to type 'Status'字面量不在允许列表(多半拼错)
KEIL5编译报错L6200E:__stdout重定义问题分析与解决 本文深入分析KEIL5编译报错L6200E中__stdout重定义问题的根源,指出因未完整定义__stderr导致与标准库stdio_streams.o冲突。提供完整重定义标准流、启用MicroLIB库等解决方案,帮助开发者彻底解决Symbol multiply defined错误,提升嵌入式开发效率。 阅读详情

相关推荐

来自工业界的知识库 RAG 服务(二),RagFlow 源码全流程深度解析

前面介绍过有道 QAnything 源码解析,通过深入了解工业界的知识库 RAG 服务,得到了不少调优 RAG 服务的新想法。因此本次趁热打铁,额外花费一点时间,深入研究了另一个火热的开源 RAG 服务RagFlow的完整实现流程,希望同样有所收获。首先依旧可以先从框架图入手,与常规的 RAG 架构进行一些比较可以看到右侧知识库被明显放大,同时最右侧详细介绍了文件解析的各种手段,比如OCR等,这些在常规的 RAG 中可能会作为一个不起眼的。

易迟的专栏 2万+

Vue Query 与 TypeScript 实战:从类型推断、类型收窄到错误类型注册

本指南聚焦 TanStack Vue Query(`@tanstack/vue-query`)在 TypeScript 项目中的完整类型体系:`useQuery` 返回值的类型推断规则、`select` 变换后的类型变化、如何正确地收窄 `data` 与 `error` 的可空类型,以及通过 `Register` 接口注册全局错误类型的进阶玩法。读完本文,你将能够在 Vue 3 + TypeScr

gitblog_00516的博客 906

从零搭建医疗化验单识别系统:深度学习+OCR实战教程(附数据集)

本文详细介绍了如何从零开始构建一个医疗化验单智能识别系统。通过融合深度学习和OCR技术,系统能够应对版式多样、内容专业的医疗单据,实现从文本检测、识别到关键信息结构化抽取的全流程。文章提供了数据集处理、模型选型、训练微调及工程化部署的实战指南,并分享了避坑经验与性能优化策略,为开发者解决医疗信息化痛点提供了完整的技术方案。

k9l0m1的博客 493

《The Concise TypeScript Book》深度解析:TypeScript 类型收窄(Narrowing)全指南

类型收窄(Narrowing)是 TypeScript 编译器在条件分支内将变量的联合类型细化为更精确类型的过程,是安全处理 `string | number`、`Dog | Cat` 这类联合类型的核心手段。本指南以开源仓库《The Concise TypeScript Book》中 [Restringimento(意语版)](https://link.gitcode.com/i/af5de70

gitblog_00115的博客 706

eICU数据库没有ventilation_event表

各位学友大家好,我是环湖医院神经外科的飞时过,很多外院的老师和我问,ventilation_event表的问题,哪怕用ChatGPT也无法正确生成,今天我给大家用SQL做一个拿来就能用的。

环湖数据科学知识共享平台 939

NTFS分区变成RAW别乱修!正确数据恢复与修复方法详解

文件系统是操作系统管理存储数据的核心机制,NTFS作为Windows主流文件系统,一旦分区识别异常,常会显示为RAW格式。分区变RAW通常意味着文件系统入口信息损坏,而非数据物理消失,但若采用错误的修复方式,如直接对RAW分区执行chkdsk /f,可能因系统无法正确识别文件系统结构,导致写入操作落在错误偏移位置,二次破坏本可恢复的数据。正确的处理思路是:先停止一切写入操作,通过扇区级镜像备份保留原始现场,再分析DBR、分区表及$MFT状态,依据诊断结果选择修复或深度扫描恢复。实际排查中,常见问题如DBR记

weixin_31155097的博客 135

Flow 类型谓词迁移实战:将 TypeScript type guards 转换为 Flow 并保留类型收窄

在 Flow 中,类型谓词(type predicate / type guard)是让 `typeof` 等运行时检查「反向」影响静态类型的关键机制:一个返回 `boolean` 的普通函数只能表达「真或假」,而带谓词的函数能告诉类型检查器「返回 `true` 时参数被收窄为什么类型」。本文以 Flow 仓库自带的 SWE-bench 风格评测用例 [type_predicates_refine

gitblog_01022的博客 471

sdc时钟约束2——多驱动时钟

sdc 多驱动时钟 master_clock

qq_40411444的博客 5529

The Concise TypeScript Book:探索 TypeScript 类型系统——结构类型、比较规则、推断与收窄深度指南

本篇指南以《The Concise TypeScript Book》(开源免费 TypeScript 教程,仓库根目录见 [README.md](https://link.gitcode.com/i/850a295f42586e9319558a01962a8610))的「探索类型系统」章节为核心骨架,系统讲解 TypeScript 语言服务(tsserver)、结构类型系统、类型比较与可赋值性规则

gitblog_00289的博客 937

Burp靶场实战:JWT签名绕过漏洞分析与利用

本文通过Burp Suite靶场实战,深入剖析了JWT签名绕过漏洞的多种攻击手法,包括签名未验证、alg:none攻击、弱密钥爆破、JWK/JKU头注入、KID路径遍历及算法混淆攻击。文章详细演示了利用过程,并提供了关键的防御指南,帮助开发和安全人员加固JWT实现,确保认证安全。

weixin_29325515的博客 598

x265开源编码器源码框架深度解析

x265开源编码器源码框架深度解析

世界那么大,我想去看看~【随心更新,看世界去了😄】 670

Qwen3-VL-30B-A3B-Instruct-MLX-6bit 6-bit 量化详解:MLX 仿射量化终极指南,质量与速度如何兼得

想在 Apple Silicon 上流畅运行强大的多模态大模型,却受困于内存?本文带你彻底看懂 **Qwen3-VL-30B-A3B-Instruct-MLX-6bit** 的 6-bit 量化原理,讲透 MLX 仿射量化(affine)+ 分组量化(group_size=64)如何让质量与速度兼得,并附完整参数解析与部署建议,助你快速上手本地运行。 --- ## 一、为什么选 6-bit:量

gitblog_01029的博客 815

Modbus RTU 详解 + FreeMODBUS移植(附项目源码)

本文全面解析Modbus RTU通信协议,详细介绍其报文格式、功能码定义及典型应用场景,并手把手指导如何将FreeMODBUS协议栈移植到嵌入式平台。内容涵盖从底层硬件驱动配置、协议栈移植到主机/从机通信测试的全流程,重点讲解移植过程中的常见问题及解决方案。文章最后提供经过实测的完整项目源码,帮助开发者快速实现稳定的Modbus RTU通信功能。

Bit_Dong的博客 2931

The Concise TypeScript Book:深入解析 TypeScript 类型收窄(Narrowing)五大核心手段

本篇技术指南以开源项目《The Concise TypeScript Book》([英文原版](https://link.gitcode.com/i/1fb98beafb1c35c33b25f7cac3deeb65))的 [西班牙语版 Restricción 章节](https://link.gitcode.com/i/c6ecb51bf1511bfa923201ef96c07118) 为核心骨架

gitblog_00071的博客 464

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

The Concise TypeScript Book 精讲:类型收窄(Narrowing)的五大机制与实战

**导读**:类型收窄(Narrowing)是 TypeScript 类型系统的核心能力之一,它让编译器在条件分支内把联合类型(union type)变量精确收缩到更具体的类型,从而在编译期拦截错误。本文以 The Concise TypeScript Book 的 [Narrowing 章节](https://link.gitcode.com/i/857e4d1aba57e93bfb55b8eb

gitblog_01036的博客 361

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

深入探索 TypeScript 类型系统:结构类型、集合模型与类型收窄实战指南

> 导读:本文是 The Concise TypeScript Book(开源 TypeScript 简明教程,仓库位于 `typescript-book`)中「探索类型系统」一章的深度解析。这一章从 TypeScript 语言服务讲起,系统梳理结构类型(Structural Typing)、类型比较规则、类型即集合的模型、类型声明/断言、属性检查、类型推断、扩展与收窄等核心机制。读完本文,你将掌

gitblog_00664的博客 421

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

TypeScript 中 Type 和 Interface 有什么区别?

比如我先声明属性 x 类型为 number,然后你再声明属性 x 为 string | numebr,就像下面这样,编译器会报错。有点像 type,可以用来代表一种类型组合,但它范围更小一些,只能描述对象结构。interface 也可以继承自 type,但只能是对象结构,或多个对象组成交叉类型(&)的 type。interface 支持声明合并,文件下多个同名的 interface,它们的属性会进行合并。当然,如果有和 type 同名的 interface,也会报错。但声明合并不行,类型必须完全一致。

m0_73257876的博客 522

OpCore-Simplify 教程:如何一键生成 OpenCore EFI(完整指南)

OpCore-Simplify 是一个菜单式黑苹果工具:丢入一份硬件报告,它自动完成兼容性校验、ACPI 补丁匹配、kext 选配与机型选择,最终产出可写盘的 OpenCore EFI 目录。本文是一份完整的 OpCore-Simplify 使用指南,适合第一次装黑苹果、不想手工改 config.plist 的用户。 ## 它替你省掉的是什么 没有 OpCore-Simplify,一份可用的

gitblog_00253的博客 183

Typescript 中的 interface 和 type 有什么区别?

TypeScript中interface 与 type的区别

楠姐的博客 733

TypeScript 原生 API 补全 typescript-eslint 依赖的检查器与类型 API:兼容性缺口收窄与工具链迁移指南

TypeScript 7 原生实现(Go 重写的编译器与语言服务)正在逐步补全其编程接口(programmatic API)。本文基于本仓库新闻文档 [typescript-native-api-adds-typescript-eslint-apis.md](https://link.gitcode.com/i/5e91fb0d1cb8507c532e548f28b8406f)(2026 年 9

gitblog_00774的博客 718

TypeScript能力自测:从interface继承到类型体操与Playwright实战

TypeScript作为静态类型系统,其核心价值在于将错误拦截在编译期,而非运行时。理解类型机制的本质,如接口继承、类型收窄、条件类型与infer推断,是开发者从“会用”走向“用得明白”的关键。在实际工程中,学会编写.d.ts声明文件并合理组织types文件夹,能有效解决第三方库类型缺失、全局类型扩展等棘手问题。同时,在Playwright自动化测试中引入类型安全设计,不仅能让测试代码更健壮,还能借助泛型与夹具提升断言的可维护性。本文以一套覆盖语法基础、工程习惯、类型抽象与实战组合的测验清单,帮助开发者系统

weixin_29306011的博客 283

TypeScript 中 type 和 interface 有什么区别?

大家好,我是前端西瓜哥,今天我们来看看 type 和 interface 的区别。

fe_watermelon的博客 551

axios 1.x TypeScript 实战指南:类型导入、请求泛型、拦截器配置与错误类型收窄

本文以 axios 仓库中官方的 TypeScript 入门示例文档([docs/fr/pages/getting-started/examples/typescript.md](https://link.gitcode.com/i/951c88bd9442dadd929f85401bfb05ce),英文原版见 [docs/pages/getting-started/examples/typesc

gitblog_00941的博客 689

深入解析 TypeScript 判别联合(Discriminated Unions):判别属性、类型收窄与穷尽性检查实战指南

判别联合(Discriminated Unions)是 TypeScript 类型系统中面向"数据形状多变"场景的核心建模工具:它以联合类型(Union Type)为基础,借助一个共享的字面量判别属性(Discriminant),让编译器在 `switch`/`if` 分支中自动收窄(narrow)变量类型,从而以类型安全的方式处理同一抽象下的不同变体。本文以《The Concise TypeSc

gitblog_00609的博客 311

Angular Query TypeScript 类型安全实战指南:从类型推断、状态收窄到 queryOptions 与错误建模

本指南聚焦于当前仓库中 Angular 适配层([packages/angular-query-experimental](https://link.gitcode.com/i/7956b8007e381843465336d2145afc2e))与 TypeScript 协作的核心议题,讲解如何让 `injectQuery`、`injectMutation` 以及配套的 `queryOptions

gitblog_00979的博客 505

交叉类型与类型标记技巧:TypeScript-New-Handbook 类型组合高级玩法

在 TypeScript 的类型系统里,**交叉类型**(Intersection Type)和**类型标记**(Type Tagging)是两把让代码更健壮的利器。本篇文章基于开源项目 TypeScript-New-Handbook(新一代 TypeScript 官方手册的孵化仓库)中的 Object Types 与 Narrowing 章节,为你拆解**交叉类型**的用法、它与 interfa

gitblog_01091的博客 685
上一篇: TypeScript 01:类型注解与类型推断
下一篇: TypeScript 03:泛型与工具类型
ZoeLandia
博客等级 码龄6年 734粉丝 183原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值