Hi!
Thanks for adding TypeScript support. However, I think that current support is not sufficient. Actually, after doing suneditor.init, we're getting type "any", so we don't have any type annotations for editor functionalities. I think that's the most crucial part because most of the logic is after instantiating the object, not before.
Another thing with the support is the fact, that currently, support is only for the main suneditor module. There's no support for plugins and locale, so in strictly typed environment we still need to add empty declaration like declare module 'suneditor/*'; to avoid TypeScript errors.
It's not critical, it's just a nice to have feature, that would be very useful for development purposes. It's much easier to browse through code suggestions from TypeScript in IDEs like WebStorm or VS Code than browsing through documentation.
Cheers!
Hi
I am not yet familiar with TypeScript.😭
Can you send me a PR?
Hi,
When I'll have some free time I can start with adding some new typings :)
Cheers!
Yeah.
Thank you so much :)
Cheers!
I've created the first PR where I've added typings that will allow using Suneditor in TypeScript without any problems. Now, the only thing left is to provide typings for the whole core which should match docs. Probably it can be done automatically from JSDOC comments, but I'm not sure of results. I will check it or just do it manually over time and send you another PR.
Hi
Thank for your contribution!
You did a lot of things I couldn't.
Thank you.
Hi, @tswistak
Is it necessary to create .d.ts files only for files in the lib folder?
If you show me an example please, I will add it.
Hi @JiHong88
It should be enough, similarly as I did for plugins and languages. I can do more specific example some time later. For now, you can do something like this to have something from the start:
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"sourceMap": true,
"allowJs": true,
"emitDeclarationOnly": true,
"checkJs": true,
"declaration": true
},
"exclude": [
"node_modules"
]
}
tsc commandThank you @tswistak
commit
I added the tsconfig.json
Is this enough?
@tswistak
The files in "lib" are not directly imported and used by the user.
Are these files needing to generate d.ts?
Hi @JiHong88,
They are not imported by user, but they can be used in main typing file, since most of logic is in there. Unfortunately TS can't properly do types with old style of creating JS objects and a lot needs to be rewritten here manually. I'm in progress of creating proper types for whole Core, probably today or tommorow I will create a PR with that. In few cases I couldn't guess a proper type, but I will leave "TODO" comment in each case. I hope it will be a good base for further work :)
@JiHong88 please check: https://github.com/JiHong88/SunEditor/pull/311
@tswistak
Thank you so much!
I will release a new version after further work :)
Hi, @tswistak
I updated all "TODO" comments and other d.ts files at the develop branch.
Can you please check that I corrected it correctly? #518075b
Thank you.
Hi @JiHong88,
Looking at the code, it looks OK to me :) . My only concern is about init function in suneditor.d.ts. I think, that it could use better return type for { create }, so user will know what he'll get after executing that create. Some time later I can download it and check how it works and maybe I will think of some way how to approach init better.
@JiHong88 everything looks good. I've just added an additional pull request https://github.com/JiHong88/SunEditor/pull/315 with small fix.
And IMO we can close that ticket :) . TypeScript works great now.
Thank you! I couldn't find a way.
It helped me a lot in studying TypeScript.
I'll release new version and let you know.
Thank you again : )
Hi @tswistak
The 2.28.3 version has been updated.
Thank you!