在 TypeScript 中,如果对象类型包含类型为 的字段never,则无法真正实例化该类型的对象。例子:
type x = { a: string; b: never };
const xx: x = { a: "asd" }; // property 'b' is missing
Run Code Online (Sandbox Code Playgroud)
我认为能够删除所有无法分配的字段可能很有用(实际上我主要认为这将是一个有趣的挑战),我的解决方案是:
/** Recursively decays all fields that are of type `never` from `T`.
* @example DecayNever<number> // yields number
* @example DecayNever<{ x: number; y: string; z: never }> // yields { x: number; y: string }
* @example DecayNever<{ x: number; y: { z: never } }> // yields { x: …Run Code Online (Sandbox Code Playgroud) 我一直在搞乱x86-16程序集并使用VirtualBox运行它.出于某种原因,当我从内存中读取并尝试将其作为角色打印时,我得到的结果与我期望的完全不同.但是,当我将字符硬编码为指令的一部分时,它工作正常.这是代码:
ORG 0
BITS 16
push word 0xB800 ; Address of text screen video memory in real mode for colored monitors
push cs
pop ds ; ds = cs
pop es ; es = 0xB800
jmp start
; input = di (position*2), ax (character and attributes)
putchar:
stosw
ret
; input = si (NUL-terminated string)
print:
cli
cld
.nextChar:
lodsb ; mov al, [ds:si] ; si += 1
test al, al
jz .finish
call putchar
jmp .nextChar
.finish:
sti
ret …Run Code Online (Sandbox Code Playgroud)