-
-
Notifications
You must be signed in to change notification settings - Fork 268
Backfill types for some dependencies #733
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
Conversation
| AccountTrackerState | ||
| > { | ||
| private ethQuery: any; | ||
| private ethQuery: EthQuery | null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This property can be null because it is not set in the constructor (or at least I didn't see that it was set in the constructor; I may be wrong).
src/assets/Standards/CollectibleStandards/ERC1155/ERC1155Standard.test.ts
Show resolved
Hide resolved
| const { erc20, logo: filePath, ...token } = (contractMap as ContractMap)[ | ||
| tokenAddress | ||
| ]; | ||
| const { erc20, logo: filePath, ...token } = contractMap[tokenAddress]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Types were added in this PR for @metamask/contract-metadata, so typecasting is no longer necessary.
| const latestBlockNumber = 3; | ||
| const numberOfRequestedBlocks = 3; | ||
|
|
||
| beforeEach(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should have been there all along and for some reason it was not causing the test to fail.
| includeNextBlock = false, | ||
| }: { | ||
| ethQuery: EthQuery; | ||
| ethQuery: EthQueryish; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An "EthQueryish" is an object that looks like an EthQuery without the full gamut of methods that EthQuery supports. It's the type of the argument that query now takes, and since it only really cares that the object has a sendAsync method, that's what this type checks for.
|
|
||
| const txNonce = | ||
| nonce || | ||
| (await query(this.ethQuery, 'getTransactionCount', [from, 'pending'])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changed because there is now a new type parameter on query that governs the type of data that it returns (as unfortunately due to the generic nature of query, we can't figure it out). The behavior is the same though, these are just type annotations.
|
|
||
| it('bNToHex', () => { | ||
| expect(util.BNToHex(new BN('1337'))).toBe('0x539'); | ||
| describe('BNToHex', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the tests on this function because I wanted to make sure it did what I expected and I found the tests lacking.
| */ | ||
| export function weiHexToGweiDec(hex: string) { | ||
| const hexWei = new BN(stripHexPrefix(hex), 16); | ||
| return fromWei(hexWei, 'gwei').toString(10); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fromWei already returns a string; this is unnecessary.
633d7fb to
3929f6c
Compare
| collectCoverageFrom: ['./src/**/*.ts'], | ||
| // TODO: Test index.ts | ||
| coveragePathIgnorePatterns: ['./src/index.ts'], | ||
| coveragePathIgnorePatterns: ['./src/index.ts', './src/gas/gas-util.ts'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My changes to this file resulted in the coverage percentage falling below our threshold, so I've disabled this file for the time being. I logged an issue to backfill these tests here: #734
d130fde to
ecd3eea
Compare
A previous commit updated the TypeScript configuration so TypeScript would better recognize type definition files whose purpose was to backfill types for existing packages. After testing, this revealed a misunderstanding of the `paths` option in `tsconfig.json`. It turns out that `paths` completely overrides how TypeScript resolves modules and locates type definition files for modules. The consequence of this option is that if a module includes type definitions, but we also supply type definitions for that module in `types/`, then our type definitions will win. This degrades the developer experience: sometimes, a package already has types, but we merely need to *augment* those types in some way. The `paths` option makes it impossible to do this. This commit keeps the `types/` directory (as it'll be important later) but informs TypeScript about the type definition files here by adding them to the `include` option in `tsconfig.json` (which was the original strategy).
Some of our internal NPM packages are still untyped. Currently we get around this by stubbing the types for these modules in a `dependencies.d.ts` file, but this merely tags everything exported from the modules as `any`. To address this, this commit adds proper types for most of the modules marked in `dependencies.d.ts` so that these types can be accessed and utilized within the code that uses these modules. The modules that are left over are those that would either take too long to fill in or those that we are planning on removing soon anyway.
|
As explained in #761, I don't think adding ambient types for these packages to this repo is the right way to go about this. I think it would make more sense (and would also be more straightforward) to just add types directly to these packages (or add the types to the DefinitelyTyped repo for ones that we don't fully control). Thoughts/comments? |
| const { ethQuery } = this; | ||
|
|
||
| if (ethQuery === null) { | ||
| return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a change in behavior. It now returns nothing instead of throwing an error.
The same goes for syncBalanceWithAddresses - it now returns an empty object rather than throwing.
|
I'm still going the route of adding types to our packages directly rather than use ambient types as I think that will be better in the end, so I'll close this, and we can use this for inspiration later if we really need to revive this. |
Some of our internal NPM packages are still untyped. Currently we get
around this by stubbing the types for these modules in a
dependencies.d.tsfile, but this merely tags everything exported fromthe modules as
any.To address this, this commit adds proper types for most of the modules
marked in
dependencies.d.tsso that these types can be accessed andutilized within the code that uses these modules. The modules that are
left over are those that would either take too long to fill in or those
that we are planning on removing soon anyway.
NOTE: These changes are not intended to be breaking. In other words, all the types here should reflect current behavior, not ideal behavior. If you see a change that could be breaking, let me know.
Fixes #728.