New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Intellisense documentation lost for remaining properties in expanded Omit<> mapped type #49909
Comments
I just realized a workaround for this, though I'm sure it's not great for performance: //
// 4: Workaround by using `keyof Omit<>`
//
type MyModifiedInterface4_DocumentationPreserved = {
[P in keyof Omit<MyInterface, 'prop3'>]: MyInterface[P];
};
class MyClass4_DocumentationPreserved implements MyModifiedInterface4_DocumentationPreserved {
prop1 = 1; // Hover doc: Documentation for prop1
prop2 = 'a'; // Hover doc: Documentation for prop2
} |
See also #50715. I believe this type of issue is why practically every UI library out there currently copies (or generates) and duplicates most of the type-information and documentation already present in Building a typed UI library is a monumental effort - and updates to standard HTML element/attribute/event types (from official IDL definitions) really ought to come with built-in platform type definitions. (This would be something that imperative types could potentially alleviate as well - imagine you could simply |
Just to add some clarity while I have the information loaded in memory: The reason this happens is that in the checker's |
Ah, here we go! It has to be an //
// 5: Filtered key remapping preserves documentation!
//
type MyModifiedInterface5_DocumentationPreserved = {
[P in keyof MyInterface as Exclude<P, 'prop3'>]: MyInterface[P];
};
class MyClass5_DocumentationPreserved implements MyModifiedInterface5_DocumentationPreserved {
prop1 = 1; // Hover doc: Documentation for prop1
prop2 = 'a'; // Hover doc: Documentation for prop2
} |
type ProperOmit<T, K extends PropertyKey> = {
[P in keyof T as P extends K ? never : P]: T[P];
// ~~~~~~~~~~~~~ P in keyof ... as P ~
}
/**
* Construct a type with the properties of T except for those in type K.
*/
type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;
/**
* From T, pick a set of properties whose keys are in the union K
*/
type Pick<T, K extends keyof T> = {
[P in K]: T[P];
// P in <keyof T> as P
}; |
Bug Report
I'm attempting to use mapped types over an interface and I want the documentation for the properties from the original interface to be preserved when the mapped interface is implemented by a class. This normally is fine unless the mapper removes some keys from the original interface. The example below actually shows that
Omit<>
and a 1-level expansion ofOmit<>
works fine to preserve documentation over the remaining properties. However, if I expand it one more time into a raw mapped type expression, then I suddenly lose documentation.Unfortunately I can't use either of the first two options in the code I'm trying to write because I'm doing conditional typing on the value side of the map.
Thanks folks!
🔎 Search Terms
omit, exclude, mapped types, documentation, tsdoc, jsdoc, properties, implements, class, hover, intellisense, vscode, quick info
🕗 Version & Regression Information
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
In VSCode, hovering over
prop1
andprop2
in the MyClass3_DocumentationLost class result in none of the documentation from MyInterface showing.🙂 Expected behavior
In VSCode, in the MyClass3_DocumentationLost class, hovering over the following props should so the corresponding documentation from MyInterface:
prop1
-> "Documentation for prop1"prop2
-> "Documentation for prop2"The text was updated successfully, but these errors were encountered: