-
Notifications
You must be signed in to change notification settings - Fork 889
Stop using the type checker in completed-docs #3376
Comments
A little update on my comment: you can now use BUT you most likely don't want to switch because: The type checker merges documentation of merged declarations: /** Doc */
interface Foo {}
class Foo {} // also has 'Doc' as JSDoc comment
// it even merges documentation for declarations that don't merge
/** MyType */
interface T {}
var T; // has 'MyType' as JSDoc comment If microsoft/TypeScript#18804 lands, the type checker will even include the JSDoc comments of base types. It only makes sense if you only want to check the JSDoc of the current AST node. But that might break users for the reasons above. |
So, to clarify, would you recommend |
That depends on how it is supposed to work. Making this change now could break some users. If you don't want JSDoc to merge (or being inherited), you change the rule to not use the type checker. I'd also like to hear what other users of the rule think about this. /cc @buu700 @reduckted |
What are the implications of dropping the type checker? It sounds like you're saying that a case like this currently doesn't flag a rule violation, but would start to do after the type checker is dropped:
In my case, we've been consistently using |
@buu700 your example contains a rule violation either way because Currently the only difference is for merged declarations as I described above: /** Foo */
interface Foo {}
class Foo {} // currently no error; without the type checker this would be an error As of [email protected] typescript starts to inherit the documentation when /** Foo */
class Foo {
}
/** @inheritdoc */
class Bar extends Foo {
} That means |
Got it, thanks for the clarification. I didn't know jsdocs could be used that way, so when you said "merge" I thought you meant that In that case, I can see how it would be an issue for users already using jsdocs that way (if that is indeed meant to be supported by the jsdoc spec), but for me it wouldn't be an issue at all. |
What's the motivation for removing the type checker? It sounds like removing the type checker would be OK. I doubt it would affect me personally, and if the only thing that really changes is the merging of declarations, then I can't see it breaking anything that isn't already questionable (declaring a class and interface with the same name seems like a strange thing to do). Having said that, if the type checker is what's providing JSDoc comments, then maybe we should continue to use that instead of, effectively, creating our own implementation. @JoshuaKGoldberg If you wanted to create a fork without the type checker, I can run it across a bunch of repos from work and see if it changes the results. |
The TypeChecker is not available in most IDE plugins. That means you will never know about missing documentation until you run tslint from command line. #2767
The TypeChecker only makes it a bit more convenient to use. We should definitely not try to duplicate the logic regarding merging and inheritance. The rest, i.e. getting JSDoc directly from an AST node, is not a big deal. |
So just to make sure I understand, if I have /**
* This is foo.
*/
export class Foo { } And I have import { Foo } from './bar';
export class Bar extends Foo { } Then if we use the type checker, Assuming that's correct, then personally, I'm OK with not using the type checker. I prefer that everything publicly exposed have JSDoc comments, even if that's just an |
@reduckted I looked at the TypeScript PR again. IIUC It does not work for class or interface declarations. It seems to only work for properties and methods (I answered the exact opposite to @buu700 above). So @buu700's example from above would actually be valid: /** Foo */
class Foo {
/** Balls */
public balls: string;
}
/** Bar */
class Bar extends Foo {
public balls: string = 'balls';
}
I agree that using |
Another difference is the handling of overload signatures: function foo(): void;
function foo(bar: string): string;
function foo(bar?: string) {
return bar;
} The TypeChecker merges the documentation of all overloads and the implementation. If any of the declarations has a documentation comment, all other declarations are automatically valid. The behavior is the same for functions and methods. |
Just thought I'd mention something about property accessors now that #3497 has been merged. Because we're using the type checker, the documentation comments from the getter and setter are merged. This means you can have comments on the getter, but not on the setter (or vice versa), and that is considered valid. If we get rid of the type checker, then we would need some sort of special handling if we wanted to keep that behaviour. |
As per @ajafff's feedback in #2415:
This should also fix #3365.
The text was updated successfully, but these errors were encountered: