-
-
Notifications
You must be signed in to change notification settings - Fork 115
Add type definitions #43
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
Conversation
This comment has been minimized.
This comment has been minimized.
Add `types` prop Append `types/index.d.ts` to `files` so it can be published on npm
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.
Nice work!! 💪
Some nits inline, and two big things:
- In all cases where a human can give a
vfile
, it could also be aBuffer
orstring
. You added that in most places I think. But, maybe we should useVFileOptions
there. As it supports some other stuff as well. Does it make sense to exportVFileOptions
fromvfile
, and use it here instead of this list ofVFile | Buffer | string
? - Can we run prettier on the typescript files as well?
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
While thinking about my typo, |
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.
Nice work, two more questions!
Alright, so we should release this. As a minor I think? It’s not breaking in any way right? |
It won't break anything. Releasing as minor version should be fine. 👍 |
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.
Thanks @Rokt33r!
Released! Thanks @Rokt33r, and also @hrajchert! |
This broke a project I have that uses both stylelint and Stencil 0.13. The dependency chain made me end up here. So any projects that were using Typescript 2.x could be broken? I might have something wrong on the compiler settings, though. As I said, this gets installed on my package because of stylelint, so I don't know why tsc would parse these definitions 🤔 |
Huh, weird, @Rokt33r, any thought on this? |
What is the error message/stacktrace?
What is the |
similar to vfile/vfile-message#3 |
Discussion on supported TypeScript versions started on Spectrum https://spectrum.chat/unified/type-definitions?thread=7c1f6266-6be2-4d0a-b599-4ff93a6d0efd |
It's complicated, because Stencil uses typescript under the hood, so I'm not 100% sure of the settings. If you're curious, it's here Just to verify, I set up a quick project with typescript 2.9 and stylelint as dependencies with a simple tsconfig: {
"compilerOptions": {
"module": "system",
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"outFile": "out.js",
"sourceMap": true
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules",
"**/*.spec.ts"
]
} If you run tsc with this config the following error a few times:
On the sample project, the build actually finishes. Stencil seems to stop what it's doing if it encounters an error, though. In any case, I was able to suppress this error by adding It seems like tsc somehow automatically parses all definitions in node_modules/@types, because I have at least one other .d.ts files in node_modules using 'unknown' and it's being ignored. I've actually checked the DefinitelyTyped repo and there's only a handful of projects that use The worst part about this is that I'm not even actually using this library, otherwise I'd be super happy to update and get the definition files 😂 |
This should be resolved by stenciljs/core@127f0d5 in stencil version 0.16.0 and above. |
Of course it will. We haven't upgraded yet, but we're planning on doing so eventually. This will still happen to every single project that uses typescript < 3 and for whatever reason, this library is in their dependency graph. In any case, I'll keep this in mind the next time I have to add types to a library through @types and make it a major, to minimize cases like mine. |
Sorry, it was a false alarm. It works fine with vscode editor but doesn't work with
Like the below:
by updating
If the file structure looks good, I'll fix this too after we resolve the versioning problem. |
Yes, adding native typings can break projects that coded their own typings for Unified For example, it broke my Unified service which had the following: type UnifiedPluginFn = (opts: unknown) => (tree: any) => void
type UnifiedPlugin = UnifiedPluginFn | [UnifiedPluginFn, any]
interface IUnifiedProcessor {
use: (plugin: UnifiedPlugin, opts?: unknown) => void
process: (htmlInput: string) => any // vfile
} Of course, |
Hello, As it is said in #43 (comment) and #43 (comment) this upgrade will affect "every single project that uses typescript < 3 and for whatever reason, this library is in their dependency graph". This happened to a project I'm working on because it depends on I see some discussions, like this microsoft/TypeScript#9731, about if @types should be a dependency, a dev dependency or a peer dependency in order to avoid these issues but I'm not sure if there is a "good" answer yet. Are you thinking on doing something on this project (like bumb new mayor version, or remove the types as direct dependencies in 7.1.1,...)? Any suggestion on what should we do? Thank you in advance. |
This comment has been minimized.
This comment has been minimized.
See the TypeScript definition discussion here https://spectrum.chat/?t=7c1f6266-6be2-4d0a-b599-4ff93a6d0efd |
This is the first try to implement type definitions for unified.
I knew there is another attempt to adding types. But, I don't think the processor should persist AST type. It would make users confused because it looks tricky and doesn't work well with presets.
https://github.com/hrajchert/unified-typings-test/blob/master/src/types/unified/unified.d.ts