-
Notifications
You must be signed in to change notification settings - Fork 2
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
Declares types for typescript #2
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2 +/- ##
=======================================
Coverage 99.54% 99.54%
=======================================
Files 1 1
Lines 222 222
=======================================
Hits 221 221
Misses 1 1 Continue to review full report at Codecov.
|
src/prettier-printer.d.ts
Outdated
@@ -0,0 +1,52 @@ | |||
declare module 'prettier-printer' { | |||
interface IDoc {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... I'm not intimately familiar with TypeScript, but given TypeScript's use of structural typing, doesn't this mean that any object is seen as a valid document? IOW, given this definition, does e.g. render(0, {foo: 'bar'})
give a type error (it probably should, because it is an error)?
Thanks! This looks basically good, but the definition interface IDoc {} seems suspicious to me, because to me it looks like any object would then be accepted as a document, which should not be the case — assuming one actually wants some amount of type safety. I'm not intimately familiar with TypeScript, however, so I might be missing something. |
Perhaps a definition like this would be a good enough approximation: type IDoc = string | IDocArray
interface IDocArray extends Array<IDoc> { } This should allow one to pass strings and arrays of documents as documents, but not arbitrary objects or numbers, for example. Of course, there are also other kinds of documents, but one should generally treat documents as abstract and never manipulate them except by using the functions from the library. |
type IDoc = string | IDocArray
interface IDocArray extends Array<IDoc> { } Much better, thank you. Updated it with your suggestion. Also helps with documentation and text editor support. |
Looks good. I'll try to find time to merge this and release a new version with the typings this evening. Thanks again for the PR! |
No description provided.