Typescript errors when including samlify in a project using typescript itself
See original GitHub issueHey tngan,
Thanks for this project. We have been using it in production since express-samlify@1.2.3 (saml idp not sp). And it has been really helpful. We are now migrating it to use the latest version. Our project is itself written in typescript and we are using samlify@2.4.0-rc5. While compiling our code (tsc), we are facing following errors. Any help will be much appreciated.
> tsc
node_modules/samlify/src/binding-post.ts:203:24 - error TS2532: Object is possibly 'undefined'.
203 const template = customTagReplacement(initSetting.logoutRequestTemplate.context);
~~~~~~~~~~~~~~~~~~~~
node_modules/samlify/src/binding-post.ts:203:24 - error TS2722: Cannot invoke an object which is possibly 'undefined'.
203 const template = customTagReplacement(initSetting.logoutRequestTemplate.context);
~~~~~~~~~~~~~~~~~~~~
node_modules/samlify/src/binding-redirect.ts:67:235 - error TS2345: Argument of type 'null' is not assignable to parameter of type 'boolean | undefined'.
67 return baseUrl + pvPair(queryParam, octetString, noParams) + pvPair(urlParams.signature, encodeURIComponent(libsaml.constructMessageSignature(queryParam + '=' + octetString, entitySetting.privateKey, entitySetting.privateKeyPass, null, entitySetting.requestSignatureAlgorithm)));
~~~~
node_modules/samlify/src/binding-redirect.ts:87:20 - error TS2532: Object is possibly 'undefined'.
87 const info = customTagReplacement(spSetting.loginRequestTemplate);
~~~~~~~~~~~~~~~~~~~~
node_modules/samlify/src/binding-redirect.ts:87:20 - error TS2722: Cannot invoke an object which is possibly 'undefined'.
87 const info = customTagReplacement(spSetting.loginRequestTemplate);
~~~~~~~~~~~~~~~~~~~~
node_modules/samlify/src/binding-redirect.ts:142:20 - error TS2532: Object is possibly 'undefined'.
142 const info = customTagReplacement(initSetting.logoutRequestTemplate, requiredTags);
~~~~~~~~~~~~~~~~~~~~
node_modules/samlify/src/binding-redirect.ts:142:20 - error TS2722: Cannot invoke an object which is possibly 'undefined'.
142 const info = customTagReplacement(initSetting.logoutRequestTemplate, requiredTags);
~~~~~~~~~~~~~~~~~~~~
node_modules/samlify/src/binding-redirect.ts:181:24 - error TS2532: Object is possibly 'undefined'.
181 const template = customTagReplacement(initSetting.logoutResponseTemplate);
~~~~~~~~~~~~~~~~~~~~
node_modules/samlify/src/binding-redirect.ts:181:24 - error TS2722: Cannot invoke an object which is possibly 'undefined'.
181 const template = customTagReplacement(initSetting.logoutResponseTemplate);
~~~~~~~~~~~~~~~~~~~~
node_modules/samlify/src/entity-idp.ts:32:3 - error TS2564: Property 'entityMeta' has no initializer and is not definitely assigned in the constructor.
32 entityMeta: IdentityProviderMetadata;
~~~~~~~~~~
node_modules/samlify/src/entity-idp.ts:50:47 - error TS2532: Object is possibly 'undefined'.
50 context: libsaml.replaceTagsByValue(entitySetting.loginResponseTemplate.context, replacement),
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/samlify/src/entity-idp.ts:82:16 - error TS2345: Argument of type '((...args: any[]) => any) | undefined' is not assignable to parameter of type '(template: string) => BindingContext'.
Type 'undefined' is not assignable to type '(template: string) => BindingContext'.
82 }, user, customTagReplacement, encryptThenSign);
~~~~~~~~~~~~~~~~~~~~
node_modules/samlify/src/entity-sp.ts:34:3 - error TS2564: Property 'entityMeta' has no initializer and is not definitely assigned in the constructor.
34 entityMeta: ServiceProviderMetadata;
~~~~~~~~~~
node_modules/samlify/src/entity-sp.ts:71:104 - error TS2345: Argument of type '((...args: any[]) => any) | undefined' is not assignable to parameter of type '(template: string) => BindingContext'.
Type 'undefined' is not assignable to type '(template: string) => BindingContext'.
71 const context = postBinding.base64LoginRequest(libsaml.createXPath('Issuer'), { idp, sp: this }, customTagReplacement);
~~~~~~~~~~~~~~~~~~~~
node_modules/samlify/src/entity.ts:64:3 - error TS2564: Property 'entityType' has no initializer and is not definitely assigned in the constructor.
64 entityType: string;
~~~~~~~~~~
node_modules/samlify/src/extractor.ts:292:9 - error TS2322: Type 'any[]' is not assignable to type 'null'.
292 value = node.map(n => n.toString());
~~~~~
node_modules/samlify/src/extractor.ts:353:9 - error TS2322: Type 'any[]' is not assignable to type 'null'.
353 attributeValue = select(fullPath, targetDoc);
~~~~~~~~~~~~~~
node_modules/samlify/src/extractor.ts:356:9 - error TS2322: Type 'any[]' is not assignable to type 'null'.
356 attributeValue = node.map(n => n.nodeValue);
~~~~~~~~~~~~~~
node_modules/samlify/src/flow.ts:78:9 - error TS2322: Type '{ samlContent: string; sigAlg: null; extract: any; }' is not assignable to type '{ samlContent: string; extract: any; sigAlg: string; }'.
Types of property 'sigAlg' are incompatible.
Type 'null' is not assignable to type 'string'.
78 const parseResult: { samlContent: string, extract: any, sigAlg: string } = {
~~~~~~~~~~~
node_modules/samlify/src/flow.ts:141:5 - error TS2322: Type 'ExtractorField[]' is not assignable to type 'never[]'.
Type 'ExtractorField' is not assignable to type 'never'.
141 extractorFields = getDefaultExtractorFields(parserType, null);
~~~~~~~~~~~~~~~
node_modules/samlify/src/flow.ts:154:7 - error TS2322: Type 'ExtractorField[]' is not assignable to type 'never[]'.
154 extractorFields = getDefaultExtractorFields(parserType, verifiedAssertionNode);
~~~~~~~~~~~~~~~
node_modules/samlify/src/flow.ts:161:5 - error TS2322: Type 'ExtractorField[]' is not assignable to type 'never[]'.
161 extractorFields = getDefaultExtractorFields(parserType, result[1]);
~~~~~~~~~~~~~~~
node_modules/samlify/src/flow.ts:171:7 - error TS2322: Type 'ExtractorField[]' is not assignable to type 'never[]'.
171 extractorFields = getDefaultExtractorFields(parserType, verifiedAssertionNode);
~~~~~~~~~~~~~~~
node_modules/samlify/src/libsaml.ts:185:39 - error TS2538: Type 'undefined' cannot be used as an index type.
185 const algAlias = nrsaAliasMapping[sigAlg];
~~~~~~
node_modules/samlify/src/libsaml.ts:305:29 - error TS2350: Only a void function can be called with the 'new' keyword.
305 sig.keyInfoProvider = new this.getKeyInfo(signingCert, signatureConfig);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/samlify/src/libsaml.ts:305:49 - error TS2345: Argument of type 'string | Buffer' is not assignable to parameter of type 'string'.
Type 'Buffer' is not assignable to type 'string'.
305 sig.keyInfoProvider = new this.getKeyInfo(signingCert, signatureConfig);
~~~~~~~~~~~
node_modules/samlify/src/libsaml.ts:306:59 - error TS2345: Argument of type 'string | undefined' is not assignable to parameter of type 'string'.
Type 'undefined' is not assignable to type 'string'.
306 sig.signingKey = utility.readPrivateKey(privateKey, privateKeyPass, true);
~~~~~~~~~~~~~~
node_modules/samlify/src/libsaml.ts:340:36 - error TS2345: Argument of type 'any[]' is not assignable to parameter of type 'ConcatArray<never>'.
Types of property 'slice' are incompatible.
Type '(start?: number | undefined, end?: number | undefined) => any[]' is not assignable to type '(start?: number | undefined, end?: number | undefined) => never[]'.
Type 'any[]' is not assignable to type 'never[]'.
Type 'any' is not assignable to type 'never'.
340 selection = selection.concat(assertionSignatureNode);
~~~~~~~~~~~~~~~~~~~~~~
node_modules/samlify/src/libsaml.ts:341:36 - error TS2345: Argument of type 'any[]' is not assignable to parameter of type 'ConcatArray<never>'.
341 selection = selection.concat(messageSignatureNode);
~~~~~~~~~~~~~~~~~~~~
node_modules/samlify/src/libsaml.ts:477:65 - error TS2345: Argument of type 'string | undefined' is not assignable to parameter of type 'string'.
Type 'undefined' is not assignable to type 'string'.
477 const decryptedKey = new nrsa(utility.readPrivateKey(key, passphrase), {
~~~~~~~~~~
node_modules/samlify/src/libsaml.ts:508:12 - error TS2339: Property 'getKey' does not exist on type '{ createXPath: (local: any, isExtractAll?: boolean | undefined) => string; getQueryParamByType: (...'.
508 this.getKey = keyInfo => {
~~~~~~
node_modules/samlify/src/metadata-idp.ts:109:36 - error TS2345: Argument of type '({ key: string; localPath: string[]; attributes: string[]; } | { key: string; localPath: string[]...' is not assignable to parameter of type 'never[] | undefined'.
Type '({ key: string; localPath: string[]; attributes: string[]; } | { key: string; localPath: string[]...' is not assignable to type 'never[]'.
Type '{ key: string; localPath: string[]; attributes: string[]; } | { key: string; localPath: string[];...' is not assignable to type 'never'.
Type '{ key: string; localPath: string[]; attributes: string[]; }' is not assignable to type 'never'.
109 super(meta as string | Buffer, [
~
110 {
~~~~~~~
...
121 },
~~~~~~~~
122 ]);
~~~~~
node_modules/samlify/src/metadata-sp.ts:85:9 - error TS2532: Object is possibly 'undefined'.
85 descriptors.KeyDescriptor.push(libsaml.createKeySection('signing', signingCert).KeyDescriptor);
~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/samlify/src/metadata-sp.ts:91:9 - error TS2532: Object is possibly 'undefined'.
91 descriptors.KeyDescriptor.push(libsaml.createKeySection('encryption', encryptCert).KeyDescriptor);
~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/samlify/src/metadata-sp.ts:97:35 - error TS2532: Object is possibly 'undefined'.
97 nameIDFormat.forEach(f => descriptors.NameIDFormat.push(f));
~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/samlify/src/metadata-sp.ts:111:11 - error TS2532: Object is possibly 'undefined'.
111 descriptors.SingleLogoutService.push([{ _attr: attr }]);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/samlify/src/metadata-sp.ts:126:11 - error TS2532: Object is possibly 'undefined'.
126 descriptors.AssertionConsumerService.push([{ _attr: attr }]);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/samlify/src/metadata-sp.ts:153:36 - error TS2345: Argument of type '{ key: string; localPath: string[]; attributes: string[]; }[]' is not assignable to parameter of type 'never[] | undefined'.
Type '{ key: string; localPath: string[]; attributes: string[]; }[]' is not assignable to type 'never[]'.
Type '{ key: string; localPath: string[]; attributes: string[]; }' is not assignable to type 'never'.
153 super(meta as string | Buffer, [
~
154 {
~~~~~~~
...
163 }
~~~~~~~
164 ]);
~~~~~
node_modules/samlify/src/metadata.ts:33:59 - error TS2345: Argument of type '({ key: string; localPath: string[]; attributes: never[]; context: boolean; } | { key: string; lo...' is not assignable to parameter of type 'ConcatArray<never>'.
Types of property 'slice' are incompatible.
Type '(start?: number | undefined, end?: number | undefined) => ({ key: string; localPath: string[]; at...' is not assignable to type '(start?: number | undefined, end?: number | undefined) => never[]'.
Type '({ key: string; localPath: string[]; attributes: never[]; context: boolean; } | { key: string; lo...' is not assignable to type 'never[]'.
Type '{ key: string; localPath: string[]; attributes: never[]; context: boolean; } | { key: string; loc...' is not assignable to type 'never'.
Type '{ key: string; localPath: string[]; attributes: never[]; context: boolean; }' is not assignable to type 'never'.
33 this.meta = extract(this.xmlString, extraParse.concat([
~
34 {
~~~~~~~
...
61 }
~~~~~~~
62 ]));
~~~~~
node_modules/samlify/src/utility.ts:116:33 - error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation.
116 return isString(passphrase) ? this.convertToString(pki.privateKeyToPem(pki.decryptRsaPrivateKey(String(keyString), passphrase)), isOutputString) : keyString;
~~~~
node_modules/samlify/src/validator.ts:16:35 - error TS2345: Argument of type 'string | undefined' is not assignable to parameter of type 'string | number'.
Type 'undefined' is not assignable to type 'string | number'.
16 const notBeforeLocal = new Date(utcNotBefore);
~~~~~~~~~~~~
node_modules/samlify/src/validator.ts:17:38 - error TS2345: Argument of type 'string | undefined' is not assignable to parameter of type 'string | number'.
Type 'undefined' is not assignable to type 'string | number'.
17 const notOnOrAfterLocal = new Date(utcNotOnOrAfter);
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Typescript errors after including all TypeScript files in .csproj
I discovered that the reason my project wasn't building successfully through Visual Studio is that I needed to include my tsconfig.json file ...
Read more >TypeScript errors and how to fix them
Below you find a list of common TypeScript errors along with the buggy code and its fixed ... error TS1006: A file cannot...
Read more >Detect JavaScript errors during compile time using TypeScript ...
We all know that TypeScript is a language that compile itself to JavaScript. During compile-time TypeScript can emit errors to a terminal, ...
Read more >@ampliflex/samlify - npm
Start using @ampliflex/samlify in your project by running `npm i ... This project is now developed using TypeScript 2.0, also support Yarn ...
Read more >Documentation - TypeScript Tooling in 5 minutes
A tutorial to understand how to create a small website with TypeScript. ... There are two main ways to get the TypeScript available...
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
@kksharma1618 Since we haven’t delivered too much in idp side, and there are a lot of paid alternatives in the market which are production ready and well-proved by other enterprises, therefore, we are only targeting user to use IDP in testing environment, but those functions are definitely production ready.
v2.4.0 contains an important security updates on sp side, so that’s why we recommend user to upgrade it. However, if it is for IDP side, there are no much differences.
That example compiles fine on my system. Trying samlify@2.4.0 and changing following line
by
got rid of all typescript errors. Thank you!
Sorry about this sidebar, but we are using your samlidp in production for a heavy traffic app. I read in your doc that we shouldn’t be using the idp part of this library. Should I look out for anything specific before migrating from 1.2.3 to 2.4.0. Closing this particular issue.