Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

"Args" property is missing in "Log" type #3190

Closed
iyarsius opened this issue Jan 6, 2025 · 1 comment
Closed

"Args" property is missing in "Log" type #3190

iyarsius opened this issue Jan 6, 2025 · 1 comment
Labels
A: Docs Area: Documentation

Comments

@iyarsius
Copy link

iyarsius commented Jan 6, 2025

What is the type of issue?

Documentation is missing

What is the issue?

Exported log type declaration is not complete, the "args" param is not defined and i need to trick with type declaration to avoid ts errors witch is not really good practice.

am i missing something or is it a incomplete type declaration ?

import { Log } from 'viem';

function processLog(log: Log) {
  return log.args // error here, no type declaration
};

if it can help, did a type to convert log signature to args, maybe it could be useful in the Log type ?

import { ParseAbiItem, AbiParametersToPrimitiveTypes, AbiParameter } from 'abitype';
import { EventSignature } from "abitype/dist/types/human-readable/types/signatures";

/**
 * Convert the signature to ABI type with `ParseAbiItem` and extract the inputs as `AbiParameter[]`.
 * So the returned type can be used in `AbiParametersToPrimitiveTypes`.
 */
type EventAbiInputs<signature extends EventSignature> = ParseAbiItem<signature> extends { inputs: infer Inputs } ?
    Inputs extends readonly AbiParameter[] ? Inputs : never
    : never;
/**
 * Not necessary but more readable, it just wrap the `AbiParametersToPrimitiveTypes` with the previous type `EventAbiInputs`.
 */
type EventArgsTypes<signature extends EventSignature> = AbiParametersToPrimitiveTypes<EventAbiInputs<signature>>;

/**
 * Create the object using both EventAbiInputs for keys and the converted types for values.
 */
type EventArgs<signature extends EventSignature> = {
    [K in EventAbiInputs<signature>[number]['name']]: EventArgsTypes<signature>[number]
}

/**
* Fixed "Log" type
*/
type Log<signature extends EventSignature> = Log & { args: EventArgs<signature> }

Where did you find it?

https://github.com/wevm/viem/blob/main/src/types/log.ts

Reproduce

@iyarsius iyarsius added the A: Docs Area: Documentation label Jan 6, 2025
@jxom
Copy link
Member

jxom commented Jan 6, 2025

We can take a look at improving this in Viem v3. Will move this as a discussion thread.

@wevm wevm locked and limited conversation to collaborators Jan 6, 2025
@jxom jxom converted this issue into discussion #3191 Jan 6, 2025

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
A: Docs Area: Documentation
Projects
None yet
Development

No branches or pull requests

2 participants