TypeScript typings are wrong.
See original GitHub issueThe TypeScript type definitions for this project appear to be incorrect. If I do import ganache from 'ganache-core'
my project will compile without trouble but will fail at runtime due to ganache
being undefined
. However, if I instead do import * as ganache from 'ganache-core'
or import { server } from 'ganache-core'
I get compile-time errors but the script runs at runtime.
I believe the proper definition should look something like this instead:
declare module 'ganache-core' {
import { Provider as Web3Provider } from "web3/providers";
export interface IProviderOptions {
account_keys_path?: string;
accounts?: object[];
allowUnlimitedContractSize?: boolean;
blockTime?: number;
db_path?: string;
debug?: boolean;
default_balance_ether?: number;
fork?: string | object;
fork_block_number?: string | number;
gasLimit?: number;
gasPrice?: string;
hardfork?: "byzantium" | "constantinople" | "petersburg";
hd_path?: string;
locked?: boolean;
logger?: {
log(msg: string): void;
};
mnemonic?: string;
network_id?: number;
networkId?: number;
port?: number;
seed?: any;
time?: Date;
total_accounts?: number;
unlocked_accounts?: string[];
verbose?: boolean;
vmErrorsOnRPCResponse?: boolean;
ws?: boolean;
}
export interface IServerOptions extends IProviderOptions {
keepAliveTimeout?: number;
}
export function provider(opts?: IProviderOptions): Provider;
export function server(opts?: IServerOptions): any;
export interface Provider extends Web3Provider {
close: (callback: Function) => void;
}
}
Do the current typings actually work for anyone? If so, how are you doing your imports? If not, I can submit a PR with the above change.
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (8 by maintainers)
Top Results From Across the Web
typescript - Handling wrong package typings - Stack Overflow
I am using a JavaScript library which is published via NPM along with TypeScript typings. Unfortunately these typings are often wrong.
Read more >TypeScript typings are not available due to wrong field in ...
Hi. Whenever I import something from this package in my TypeScript project, I get an error saying that the declarations could not be...
Read more >You Might Be Using Typescript Wrong... - YouTube
I'm getting increasingly tired of the "but TS is so much woooooork" comments so I figured I'd do a rant.If you have friends...
Read more >Handbook - Basic Types - TypeScript
The most basic datatype is the simple true/false value, which JavaScript and TypeScript call a boolean value. ts. let isDone : boolean =...
Read more >TypeScript Programming with Visual Studio Code
Or, if the built-in formatter is getting in the way, set "typescript.format.enable" to false to disable it. For more specialized code formatting styles,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes,
IProviderOptions
is only type, and doesn’t have a corresponding runtime component, whereasprovider
andserver
are both types AND have a runtime component (the function). When coding, TypeScript recognizes if you are writing runtime code or type code, and only gives you appropriate hints.examples:
I’m sure there is a better way of explaining it, but hopefully this helps clear things up for you.
I have observed that when you type next to a
:
of a var while specifying type, it gives more suggestions.Hope this helps