surveyjs_angular_cli icon indicating copy to clipboard operation
surveyjs_angular_cli copied to clipboard

TS7016 Could not find a declaration file for module surveyjs-wigets

Open zenithA opened this issue 5 years ago • 3 comments

After installing the library, the import is not possible becuase the missing declaration file (.d.ts). I have attempted to create one in @types, but might happen that it is still wrongly declared, as for instance elements of type "datepicker" are still not visible Questions:

  1. Is it correct to create a custom d.ts file for the library or there is another better option?
  2. If it is, what should this file contain in order to be able to use elements of type "datepicker" (the others do not matter, so declaration for any other type is not needed) ?

zenithA avatar Jul 16 '19 08:07 zenithA

This sample angular-cli repo also uses surveyjs-widgets package and it builds and runs ok for me. We're using surveyjs-widgets via the following code:

import * as widgets from 'surveyjs-widgets';

Please check this file - https://github.com/surveyjs/surveyjs_angular_cli/blob/master/src/app/survey.component.ts

If you are still experiencing the issue please provide us with a steps to reproduce the issue.

According to the second question - surveyjs-widgets are using 3rd party JavaScrip libraries and probably some of them don't have typings as well. And this quesion should be asked in the corresponding repository, e.g. here for jQuery datepicker - https://github.com/jquery/jquery-ui

tsv2013 avatar Jul 16 '19 11:07 tsv2013

The problem is that for an environment configured with the following:

  • typescript - v3.2.4
  • survey-angular: 1.0.98
  • surveyjs-widgets: 1.0.98
  • jquery: 3.1.1
  • jquery-ui: 1.12.1
  • "noImplicitAny": true in tsConfig.json (I can't allow it to be set to false, but even if it is, the widget is still not loaded) => I get a ts compile error: TS7016 Could not find a declaration file for module surveyjs-widgets ( this is caused by the fact that the library is missing the d.ts file)

If setting noimplicitAny=false, the compile error disappears, but the datepicker element from surveyjs-widgets is not loaded and the following error is returned: JsonIncorrectTypeError: The property type is incorrect in the object. Please take a look at property: 'elements'. The following types are available: 'matrixdropdownbase', 'matrixdropdown', 'matrixdynamic', 'matrix', ...", etc

I have also tried creating a surveyjs-widgets.d.ts file where to declare the module, where I have included the following: declare module 'surveyjs-widgets' { export function jqueryuidatepicker(survey: any): any; } But also, even if the ts compile error disappears, the datepicker is not loaded and the error JsonIncorrectTypeError is still shown

zenithA avatar Jul 19 '19 07:07 zenithA

It is a difficult problem, a fast solution is create the d.ts file in @types like you do it, but we can declare the next module to allow any types:

declare module 'surveyjs-widgets' {
    var _a: any;
    export = _a;
}

about the datepicker, I don't know yet.

pj-alvarado10 avatar Oct 25 '21 23:10 pj-alvarado10