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

ts: Change the Program constructor's idl parameter type to any #3181

Conversation

acheroncrypto
Copy link
Collaborator

Problem

TypeScript's automatic inference of JSON files messes with the ability to use Program constructor without additional casting:

import * as idl from "./idl/my_program.json";
import type { MyProgram } from "./types/my_program";

const program = new Program(idl as unknown as MyProgram, provider);

Casting to unknown or any is necessary when TypeScript automatically infers the type of the JSON file.

People rightfully ask how to handle this situation e.g. #2914 (comment).

Summary of changes

Change the Program constructor's idl parameter type to any, so that we can simplify constructing programs:

const program = new Program<MyProgram>(idl, provider);

or

const program: Program<MyProgram> = new Program(idl, provider);

Copy link

vercel bot commented Aug 19, 2024

@acheroncrypto is attempting to deploy a commit to the coral-xyz Team on Vercel.

A member of the Team first needs to authorize it.

@acheroncrypto acheroncrypto merged commit 04b2153 into coral-xyz:master Aug 19, 2024
0 of 9 checks passed
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.

1 participant