Improve type annotations (#271)

* Add js-yaml type definition

* Improve type annotations

* Store values to properties
This commit is contained in:
woxtu
2022-05-08 01:25:05 +09:00
committed by GitHub
parent 4ec24a919a
commit a0c7b7653a
3 changed files with 19 additions and 6 deletions

View File

@@ -4371,6 +4371,12 @@
"integrity": "sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==",
"dev": true
},
"@types/js-yaml": {
"version": "4.0.5",
"resolved": "https://registry.npmjs.org/@types/js-yaml/-/js-yaml-4.0.5.tgz",
"integrity": "sha512-FhpRzf927MNQdRZP0J5DLIdTXhjLYzeUTmLAu69mnVksLH9CJY3IuSeEgbKUki7GQZm0WqDkGzyxju2EZGD2wA==",
"dev": true
},
"@types/json-schema": {
"version": "7.0.11",
"resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.11.tgz",

View File

@@ -17,6 +17,7 @@
"@rollup/plugin-node-resolve": "^11.0.0",
"@rollup/plugin-typescript": "^8.3.2",
"@tsconfig/svelte": "^1.0.0",
"@types/js-yaml": "^4.0.5",
"@typescript-eslint/eslint-plugin": "^5.20.0",
"@typescript-eslint/parser": "^5.20.0",
"autoprefixer": "^10.4.7",

View File

@@ -16,7 +16,7 @@ export class PyEnv extends HTMLElement {
shadow: ShadowRoot;
wrapper: HTMLElement;
code: string;
environment: any;
environment: unknown;
runtime: any;
env: string[];
paths: string[];
@@ -32,22 +32,28 @@ export class PyEnv extends HTMLElement {
this.code = this.innerHTML;
this.innerHTML = '';
const env = [];
const env: string[] = [];
const paths: string[] = [];
this.environment = jsyaml.load(this.code);
if (this.environment === undefined) return;
for (const entry of this.environment) {
for (const entry of Array.isArray(this.environment) ? this.environment : []) {
if (typeof entry == 'string') {
env.push(entry);
} else if (entry.hasOwnProperty('paths')) {
for (const path of entry.paths) {
paths.push(path);
} else if (entry && typeof entry === 'object') {
const obj = <Record<string, unknown>>entry;
for (const path of Array.isArray(obj.paths) ? obj.paths : []) {
if (typeof path === 'string') {
paths.push(path);
}
}
}
}
this.env = env;
this.paths = paths;
async function loadEnv() {
await loadPackage(env, runtime);
console.log('environment loaded');