{
[P in K]: never;
};
function as<KTagged>(
x: KTagged extends Tagged<infer R, any> ? R : never
): KTagged {
return (x as unknown) as KTagged;
}
type IsVisible = Tagged<boolean, "IsVisible">;
const t = as<IsVisible>(true); // KTagged extends Tagged<infer R, any> ? R : never === IsVisible
type IsVisible = Tagged<number, "IsVisible">;
const t = as<IsVisible>(44); // ок
https://www.typescriptlang.org/play/?ssl=4&ssc=45&pln=4&pc=20#code/C4TwDgpgBAKghgcwRAJgHhgGigaShAD2AgDsUBnKAawhAHsAzKOEkAPigF5YoAyKAEoQAxnQBO6HNhIQAbhDFsA3AChQkWImQoY4CBg7cY+IqQqakqNAEsSDBYOy37Y3BwD8UAKIFhAGwBXFH0BbCFRCTQpKBl5RQ4ALhi5BVUVBgCSYWBrOhJmcij4SxQ2AAoVKCgCJOLtXUgirVQ2FQBKJJw61CgAb0qoMQhgALF8soICqEyqEjoAdxI2qa7mlFUAXzU9KABJcgA1a3JrACM-CAAmLgttNFO6OguWbAAifaOT84hX5RVREjkYBQYHcOCFD7HM4XS7lYBiAIQNpKKAAelRuG6KBMxDIlCxNjsDlCzFYHkEUCSsQcnFpe0OUO+Km2GkhXwuNwJJACAFtTgo3mzoVdfqoAUCQdcwRCGeyIOUAMwK5FojGAPhBAFwgQA Вот, так он работает для number, но для boolean - never
Обсуждают сегодня