kevinoleary19 / Angular-2-Datepicker

A minimalist datepicker inspired by Google's material design
70 stars 71 forks source link

Having trouble using this in AoT compiled apps #68

Open pdavin-zz opened 7 years ago

pdavin-zz commented 7 years ago

I'm having trouble using this in our AoT (Ahead of Time compilation) build. AoT is necessary for any Angular 2 app that wants decent production performance.

I think the difficulty is mainly due to absence of .d.ts files for your library. This causes ngc, when compiling my app, to try to also compile your library's .ts files. This doesn't work since they're not under rootDir - since it's good practice to keep third party libraries in a separate directory tree from your own app code.

I tried compiling the library with 'npm run ngc', but it seems that is broken in a couple ways.

The "files" target in tsconfig-aot.json references integration-test/ files - that directory doesn't exist in the git clone. I changed files to [ "src/main.ts", "src/datepicker.module.ts"] and got past this issue.

Also noImplicitAny: true is turned on, but the code doesn't pass noImplicitAny rules. Turning that off got me past this issue.

Also the compiler option "declaration": true should be present in order to create .d.ts files. When I turn this on however I get these errors: Error: Error at /.../Angular-2-Datepicker/src/datepicker.component.ts:331:33: Public property 'dateFormat' of exported class has or is using private name 'DateFormatFunction'. Error at /.../Angular-2-Datepicker/src/datepicker.component.ts:702:43: Return type of public method from exported class has or is using private name 'ValidationResult'. Error at /.../Angular-2-Datepicker/src/datepicker.component.ts:722:40: Return type of public method from exported class has or is using private name 'ValidationResult'.

This is because the interfaces are used in the types of public @Inputs. Adding "export" before the interface declarations fixed this.

After all this I was able to generate .d.ts files for the library. However I'm still having ngc compilation issues importing the DatepickerModule - but that is probably outside the scope of this issue.

zskhan commented 7 years ago

This issue is also resolved in this PR https://github.com/koleary94/Angular-2-Datepicker/pull/52 Its in review. If you want it on urgent basis you can use ng-material-datepicker