8000 Improve type annotations (#271) · sarvjeetdev/pyscript@a0c7b76 · GitHub < 10000 body class="logged-out env-production page-responsive" style="word-wrap: break-word;">
Skip to content

Commit a0c7b76

Browse files
authored
Improve type annotations (pyscript#271)
* Add js-yaml type definition * Improve type annotations * Store values to properties
1 parent 4ec24a9 commit a0c7b76

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

pyscriptjs/package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyscriptjs/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"@rollup/plugin-node-resolve": "^11.0.0",
1818
"@rollup/plugin-typescript": "^8.3.2",
1919
"@tsconfig/svelte": "^1.0.0",
20+
"@types/js-yaml": "^4.0.5",
2021
"@typescript-eslint/eslint-plugin": "^5.20.0",
2122
"@typescript-eslint/parser": "^5.20.0",
2223
"autoprefixer": "^10.4.7",

pyscriptjs/src/components/pyenv.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class PyEnv extends HTMLElement {
1616
shadow: ShadowRoot;
1717
wrapper: HTMLElement;
1818
code: string;
19-
environment: any;
19+
environment: unknown;
2020
runtime: any;
2121
env: string[];
2222
paths: string[];
@@ -32,22 +32,28 @@ export class PyEnv extends HTMLElement {
3232
this.code = this.innerHTML;
3333
this.innerHTML = '';
3434

35-
const env = [];
35+
const env: string[] = [] DF80 ;
3636
const paths: string[] = [];
3737

3838
this.environment = jsyaml.load(this.code);
3939
if (this.environment === undefined) return;
4040

41-
for (const entry of this.environment) {
41+
for (const entry of Array.isArray(this.environment) ? this.environment : []) {
4242
if (typeof entry == 'string') {
4343
env.push(entry);
44-
} else if (entry.hasOwnProperty('paths')) {
45-
for (const path of entry.paths) {
46-
paths.push(path);
44+
} else if (entry && typeof entry === 'object') {
45+
const obj = <Record<string, unknown>>entry;
46+
for (const path of Array.isArray(obj.paths) ? obj.paths : []) {
47+
if (typeof path === 'string') {
48+
paths.push(path);
49+
}
4750
}
4851
}
4952
}
5053

54+
this.env = env;
55+
this.paths = paths;
56+
5157
async function loadEnv() {
5258
await loadPackage(env, runtime);
5359
console.log('environment loaded');

0 commit comments

Comments
 (0)
0