I'm interested in utilizing a CDN to access a JSON validation library, as it's expected to provide faster performance (due to retrieving the file from the nearest server within the CDN).
The JSON validation library in question can be found here: https://github.com/epoberezkin/ajv#using-in-browser
Upon clicking on the link, I was directed to this CDN:
To integrate it into my HTML code:
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ajv/4.10.4/ajv.min.js" integrity="sha256-LtA3VfycAam30/5e2Fq1f2tg8eIiFMOVWp1NDd6jmUU=" crossorigin="anonymous"></script>
</head>
Next, regarding typings... I executed
npm install --save-dev @types/ajv
and the installation went smoothly.
The path to the package.json file for @types/ajv is:
{
"_args": [
[
{
"raw": "@types/ajv",
"scope": "@types",
"escapedName": "@types%2fajv",
"name": "@types/ajv",
"rawSpec": "",
"spec": "latest",
"type": "tag"
},
"C:\\Users\\si556577\\Documents\\SSWebApp\\app\\Iag.DI.Web.SupplierApp"
]
],
"_from": "@types/ajv@latest",
"_id": "@types/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3253584472031c021c02">[email protected]</a>",
"_inCache": true,
"_installable": true,
"_location": "/@types/ajv",
"_npmOperationalInternal": {
"host": "packages-12-west.internal.npmjs.com",
"tmp": "tmp/ajv-1.0.0.tgz_1482502603556_0.6872997884638608"
},
"_npmUser": {
"name": "types",
"email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="681c1b45061805451c11180d1b2805010b1a071b070e1c460b0705">[email protected]</a>"
},
"_phantomChildren": {},
"_requested": {
"raw": "@types/ajv",
"scope": "@types",
"escapedName": "@types%2fajv",
"name": "@types/ajv",
"rawSpec": "",
"spec&q...
This also resulted in an addition to the package.json file:
"devDependencies": {
"@types/ajv": "^1.0.0",
In my actual code, I utilize these typings like so:
validateJSONSchema(json) {
var ajv = new Ajv();
var valid = ajv.validate(this.schema, json);
if (!valid) {
console.log(ajv.errors);
return false;
} else {
return true;
}
}
While the code functions correctly, I encountered a compile-time error in VS Code: Cannot find name "Ajv"
Is there a way to resolve this issue with the typings? My experience with typings has only involved locally installed packages rather than CDNs. Can typings even function properly when a CDN is being used?