How to add custom typings to a library build?
See original GitHub issueType of Issue
[x] Bug Report
[ ] Feature Request
Description
I’m working on a project where unfortunately there are some events polluting the window object… nobody is proud of that here but that’s what we got 🙈
When running angular-cli -> ng build, the angular-cli is able to compile a specific ts file that contains a call to window.specialEvent but when running ng-packagr -p we get: Property ‘specialEvent’ does not exist on type ‘Window’. I have a local file window.d.ts that contains:
declare global {
export interface Window {
specialEvent(eventName: string, data: any): boolean;
}
}
this is our tsconfig.json
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
}
}
Expected Behaviour
Angular library is build with success 😎
Version Information
ng-packagr: ^1.3.0
node: v6.9.1
@angular/cli: 1.4.5,
@angular: ^4.2.4
rxjs: ^5.4.2,
zone.js: ^0.8.14
ps. thanks in advance for your support and thanks for this great project!
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:10 (5 by maintainers)
Top Results From Across the Web
How to add custom types into the TypeScript project - drag13.io
Create custom typings · Create a root folder for your types. You can give any name for it but let it be types...
Read more >How to add custom "typings" in typescript 2.0 / 3.0
You can create local custom typings just for your project, where you can declare types for JS libraries. For that, you need to:....
Read more >TypeScript: Adding Custom Type Definitions for Existing ...
In these circumstances, you have to add your own custom type definitions for the libraries. This article will show you how to that....
Read more >Adding Custom Type Definitions to a Third-Party Library
Try installing it via npm or yarn. However, if it is one of the many libraries out there that doesn't have any public...
Read more >How to add custom types to a javascript library
Create a file with extension .d.ts , generally you'll put this file on dist folder. Now here you can add your custom types....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @x1c0,
thanks for reporting.
My recommendation is to either use typings from
node_modules/@types/<*>
or reference a custom*.d.ts
file by a triple slash refertence. The latter is a proven solution for working with custom (proprietary / legacy) libs - maybe, you even need thed.ts
file by hand - at least it works well with at least one proprietary lib that I use.Stumbled across this from a google search. Just to clarify, once you have created the typings file (i.e.
projects/lib-project/src/typings.d.ts
) Be sure to add it to the types array inprojects/lib-project/tsconfig.lib.ts
This worked for me; now VSCode recognizes the namespaces referenced in typings.d.ts and the tsconfig.lib “types” addition helps ng-packagr find the custom typings file.