Skip to content

Commit

Permalink
Fix type errors in older versions of Angular
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinpalkovic committed Mar 17, 2024
1 parent 0c93db1 commit 762a61f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions code/frameworks/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
},
"builders": "dist/builders/builders.json",
"bundler": {
"post": "./scripts/postbuild.js",
"tsConfig": "tsconfig.build.json"
},
"gitHead": "e6a7fd8a655c69780bc20b9749c2699e44beae17"
Expand Down
17 changes: 17 additions & 0 deletions code/frameworks/angular/scripts/postbuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* This postbuild fix is needed to add a ts-ignore to the generated public-types.d.ts file.
* The AngularCore.InputSignal and AngularCore.InputSignalWithTransform types do not exist in Angular
* versions < 17.2. In these versions, the unresolved types will error and prevent Storybook from starting/building.
* This postbuild script adds a ts-ignore statement above the unresolved types to prevent the errors.
*/

const fs = require('fs');
const path = require('path');

const filePath = path.join(__dirname, '../dist/client/public-types.d.ts');
const fileContent = fs.readFileSync(filePath, 'utf8');
const newContent = fileContent.replaceAll(
/(\[K in keyof T\]: T\[K\] extends AngularCore.InputSignal)/g,
' // @ts-ignore\n $1'
);
fs.writeFileSync(filePath, newContent, 'utf8');

0 comments on commit 762a61f

Please sign in to comment.