-
Notifications
You must be signed in to change notification settings - Fork 2
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
Incorrect types for Payload #6
Comments
Are you on the latest version? My code succeeds when I try to recreate your example: import {
DisclosureFrame,
HasherAlgorithm,
SdJwt,
SignatureAndEncryptionAlgorithm,
} from "jwt-sd";
type JWTHeader = {
alg: string;
typ: string;
};
function create<Payload extends Record<string, unknown>>(
payload: Payload,
disclosureFrame: DisclosureFrame<Payload>
): Promise<SdJwt<JWTHeader, Payload>> {
const sdJwt = new SdJwt<JWTHeader, Payload>(
{
header: {
alg: SignatureAndEncryptionAlgorithm.EdDSA,
typ: "sd-jwt",
},
payload: payload,
},
{
saltGenerator: () => "salt",
signer: () => new Uint8Array(32).fill(42),
hasherAndAlgorithm: {
algorithm: HasherAlgorithm.Sha256,
hasher: () => new Uint8Array(32).fill(32),
},
disclosureFrame,
}
);
return Promise.resolve(sdJwt);
}
type Foo = {
foo: string;
};
create<Foo>({ foo: "hi!" }, { foo: true, __decoyCount: 2 }).then(console.log) output:
|
Ahhh I see. You are using an A Or, you do not define the type create({ foo: "hi!" }, { foo: true, __decoyCount: 1 }).then(console.log); This has full type completion on the disclosureframe even if to make the interface with |
@berendsliedrecht Ty very much :) |
I moved the create function into a class because I need to define the signer dynamic at runtime like
But when I call it I get different errors:
This will throw an error for name:
Type 'string' is not assignable to type 'boolean | undefined'.ts(2322)
When I remove the
[key: string]: any
definition from my interface, it throws:Type 'Foo' does not satisfy the constraint 'Record<string, unknown>'. Index signature for type 'string' is missing in type 'Foo'.
I think I am defining the types wrong when transforming the examples to a class based approach. An example of it in the code folder would help a lot! :)
The text was updated successfully, but these errors were encountered: