Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript Support added #2

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

Ananthakr
Copy link

To support absolute type schema check at function calling time by initializing the export with schema rather than passing it during function call. This makes sure the key passed to get/set is within the schema and takes the relevant type from the schema.

import pandora from "@faizaanceg/pandora";

type StorageSchema = {
   username: string;
}

let pandora: pandora<StorageSchema>

pandora.set("username", "pandora"); // this'll work
pandora.set("username",  1); // this should fail

let name: string = pandora.get("username"); // this'll work
let name: string = pandora.get("username", "pandora"); // this'll work
let name: string = pandora.get("username", 1); // this should fail

Related issue - #1

.gitignore Outdated Show resolved Hide resolved
example-types.ts Outdated Show resolved Hide resolved
tsconfig.json Show resolved Hide resolved
index.d.ts Outdated Show resolved Hide resolved
package.json Show resolved Hide resolved
tsconfig.json Outdated Show resolved Hide resolved
tsconfig.json Outdated Show resolved Hide resolved
index.d.ts Outdated Show resolved Hide resolved
example.ts Outdated Show resolved Hide resolved
index.d.ts Outdated Show resolved Hide resolved
Co-authored-by: ​Faizaan <[email protected]>
index.d.ts Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants