我希望在一个类型脚本类型中需要特定的嵌套属性。就像PartialExcept
所做的一样,除了嵌套。
export type PartialExcept<T, K extends keyof T> = Required<Pick<T, K>> &
Partial<T>;
因此,我可以在类型帮助器中指定所有内容,而不是添加这些联合。
type Game = {
home: PartialExcept<
Team,
'name' | 'description'
> & {
goals: Required<Goal>[];
metadata: PartialExcept<
Metadata,
'time' | 'period'
>;
};
};
类型在哪里
type Team = {
name?: string
description?: string
goals?: Goal[]
metadata?: Metadata
}
type Metadata = {
{
time?: string
period?: number
shots?: number
}
type Goal = {
scorer?: string
number?: string
}
1条答案
按热度按时间ffscu2ro1#
有人实际上解决了它,不完全是我要找的语法,但它的工作
https://www.typescriptlang.org/play?#code/PQKhCgAIUhZBDA1gUwM6VcgNsgxgF2QBNIAzAS2yPQCdkBHAV3LqIBpJ4A7E-AC2SQ6qfJAD2AB3zkxXeFigRokAAIT4NeAFtIAFUgBaSP0Fia5AObk5WYwE8JyRavWadAaUPGBkFHfT4YpAARoJ0TCzEGMiu8IQkwXackIxcMlyQAD6QyAAekADkqLhmyAVZhRZi8uXZBdJaZYrA4PgOggAiyDEAChrS8gCiubgx+AA8+nmEPOhiwQBWePgcntPIs5AAcmjx7sh2APKkkwB8p5AAvJAAqmmyumIAklyENJgE6eN9NANYw6MpHcvrpVhdsl1ev1yPIzqdwK12rd7lxHi83h9pLJxjcLtcoJAABQ3HK5GbUW6QAD8RI0FgAXLcAJRXC4ANzE5BIjK4yDZyBoLPWm0JhLpjOspAFkCeLMu7M5RBZNKekB5fIFCLajkgPz+ALGwOxoMgazJGwpInMXAseIJZvJ6AABgASADekul7gAYiwRKTHZBhvhNARxn4xKQ9BwrdZbQBfAB07s9NFNACVdgGLehYzb406CZBqZA3ZAANr7JLWU2+974AC6jKr2c2Eaj+hpeph-xGhpRk0rBwbq0zIgu6v5afjRbVptbFPbehLZaH1Yy7ib21kW0YWCw8GCOEHVYbF3jc95U4A3FqkZCJN3Ybo8cvhRT5ksCCvZ+WepAayXXQGypRk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