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

@@ -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');