firepad icon indicating copy to clipboard operation
firepad copied to clipboard

Distribute Typescript type file(s, *.d.ts) to allow type-safe use from Typescript

Open toasterpic opened this issue 4 years ago • 2 comments

TS has support for generating *.d.ts for js by flags(allowJs and declarations) in version 3.7, however it fails when applied to both the distributed firepad 1.5.10 as well as the latest sources.

Version info

Firepad: 1.5.10

Test case

tsc --allowJs --declaration --emitDeclarationOnly ./node_modules/firepad/dist/firepad.js

Expected behavior

valid firepad.d.ts created next to firepad.js

Actual behavior

node_modules/firepad/dist/firepad.js:14:1 - error TS9005: Declaration emit for this file requires using private name 'Entity'. An explicit type annotation may unblock declaration emit.

14 (function (name, definition, context) {
   ~

node_modules/firepad/dist/firepad.js:14:1 - error TS9005: Declaration emit for this file requires using private name 'Firepad'. An explicit type annotation may unblock declaration emit.

14 (function (name, definition, context) {
   ~

node_modules/firepad/dist/firepad.js:14:1 - error TS9005: Declaration emit for this file requires using private name 'Headless'. An explicit type annotation may unblock declaration emit.

14 (function (name, definition, context) {
   ~

node_modules/firepad/dist/firepad.js:14:1 - error TS9005: Declaration emit for this file requires using private name 'MonacoAdapter'. An explicit type annotation may unblock declaration emit.

14 (function (name, definition, context) {
   ~

node_modules/firepad/dist/firepad.js:14:1 - error TS9005: Declaration emit for this file requires using private name 'RichTextCodeMirrorAdapter'. An explicit type annotation may unblock declaration emit.

14 (function (name, definition, context) {
   ~

node_modules/firepad/dist/firepad.js:14:1 - error TS9005: Declaration emit for this file requires using private name 'TextOperation'. An explicit type annotation may unblock declaration emit.

14 (function (name, definition, context) {
   ~


Found 6 errors.

Test case

  1. git clone https://github.com/FirebaseExtended/firepad.git
  2. tsc --init
  3. tsc --allowJs --declaration --emitDeclarationOnly -p .

Actual behavior

examples/firepad-userlist.js:1:1 - error TS9005: Declaration emit for this file requires using private name 'FirepadUserList'. An explicit type annotation may unblock declaration emit.

1 var FirepadUserList = (function() {
  ~~~

lib/monaco-adapter.js:1:1 - error TS9005: Declaration emit for this file requires using private name 'MonacoAdapter'. An explicit type annotation may unblock declaration emit.

1 'use strict';
  ~~~~~~~~~~~~


Found 2 errors.


toasterpic avatar Apr 27 '20 10:04 toasterpic

@toasterpic thanks for the suggestion and the detailed information. Firepad is a pretty old library so it doesn't surprise me that it needs some work to be TS-ready. If you or someone else wants to send a PR to add d.ts files (or just fix the errors above) I would be happy to review it.

samtstern avatar Apr 27 '20 12:04 samtstern

@toasterpic If your usecase concerns with Monaco Editor, I can offer you to use @hackerrank/firepad for the time being. It's complete rewrite of the library in TS with modern build system powered by Webpack/ESM, but I am yet to integrate Ace and CodeMirror to and waiting for that to get completed before pulling it upstream.

0xTheProDev avatar Jun 26 '21 12:06 0xTheProDev