feat: implement generic type or any

This commit is contained in:
Ayo 2023-07-16 20:14:47 +02:00
parent a8ccf35cc7
commit 941d8da1ad
3 changed files with 10 additions and 7 deletions

5
package-lock.json generated
View file

@ -1,12 +1,13 @@
{
"name": "resume",
"name": "@ayco/astro-resume",
"version": "0.0.7",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "resume",
"name": "@ayco/astro-resume",
"version": "0.0.7",
"license": "MIT",
"dependencies": {
"astro": "^2.8.3"
}

View file

@ -11,9 +11,11 @@ const data = {
<script>
import {resume} from '../resume';
console.log(resume('astro-obj'));
const data = resume<{hello:string}>('astro-obj');
data.hello;
const renderDiv = document.querySelector('#render-here');
if (renderDiv) {
renderDiv.innerHTML = JSON.stringify(resume('astro-obj'))
renderDiv.innerHTML = JSON.stringify(data)
}
</script>
</script>

View file

@ -1,3 +1,3 @@
export function resume(id: string): Object {
export function resume<T = any>(id: string): T {
return JSON.parse(document.querySelector<HTMLTextAreaElement>(`#${id}`)?.value ?? '')
}
}