【发布时间】:2021-11-20 10:54:46
【问题描述】:
我有一个接受两个参数的函数。基本上我希望 Typescript 进行检查,第二个参数不能包含第一个参数中的键。 TS Sandbox
interface Todo {
title: string;
description: string;
}
// here I hardcoded the 'title' key on the Omit utility type. My question is, how to make this dynamic, based on the key on the left argument.
function test<T>(left: Partial<T>, right: Partial<Omit<T, 'title'>>): void {
console.log(left, right);
};
// expected TS error here, because title already exists on the left object
test<Todo>({ title: 'A' }, { description: 'B', title: 'AB' })
任何帮助将不胜感激..
【问题讨论】:
-
let title = "Hello world"; let description = "你好世界,欢迎来到宇宙。";然后像这样使用includes()函数:description.includes(title)
标签: typescript type-constraints