Skip to content
This repository was archived by the owner on Dec 21, 2021. It is now read-only.

Conversation

@teogeb
Copy link
Contributor

@teogeb teogeb commented Feb 16, 2021

Added basic TypeScript support to the project. Converted most of the public methods to TypeScript.

TODO:

  • many methods are currently marked with Todo meta type: need to define valid types for those before 5.x is published
  • annotated some JS code with @ts-expect-error: need to check if some of the TS warnings are actually bugs
  • optionality of some method parameters has not yet defined 100%: there may be parameters that are optional, but are not marked with question mark annotation or null|undefined
  • none of the methods/fields have been marked as private: we should set valid privacy level at least to all StreamrClient public methods and fields

@linear
Copy link

linear bot commented Feb 16, 2021

NET-177 TypeScriptify streamr-client-javascript

Convert the JS-client from TypeScript. The highest priority is to convert all methods that are publicly available to the end-users.

Copy link
Contributor

@timoxley timoxley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few minor things, but overall lgtm 👍 good work

}

async getOrCreateStream(props: { id?: string, name?: string }) {
return this.streamEndpoints.getOrCreateStream(props)
Copy link
Contributor

@timoxley timoxley Feb 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So all these wrapped functions should probably just forward the exact signature of the functions they're wrapping, rather than manually duplicating the type definition in multiple places:

getOrCreateStream(...args: Parameters<StreamEndpoints['getOrCreateStream']>): ReturnType<StreamEndpoints['getOrCreateStream']> {
    return this.streamEndpoints.getOrCreateStream(props)
}

Might be able to parameterise this and make a helper type FnWrapper<T, N> = ??? but that's beyond my ability at this point.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, these could be mixins, either using the class factory method they describe here or the "alternative" method, which would be pretty close to how it was set up before: https://www.typescriptlang.org/docs/handbook/mixins.html

import Stream, { StreamProperties } from './stream'
import { ExternalProvider, JsonRpcFetchFunc } from '@ethersproject/providers'

export interface StreamrClientOptions {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should go into ./Config.ts and could probably be largely inferred from defaults.

dataUnion: null, // Give a "default target" of all data union endpoint operations (no need to pass argument every time)
tokenAddress: '0x0Cf0Ee63788A0849fE5297F3407f701E122cC023',
minimumWithdrawTokenWei: '1000000', // Threshold value set in AMB configs, smallest token amount to pass over the bridge
// @ts-expect-error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah these should probably be undefined or set to some default value or fix the type to be | null for now, IMO better than // @ts-expect-error

@timoxley timoxley merged commit 448485f into 5.x Feb 17, 2021
@timoxley timoxley deleted the typescript branch February 17, 2021 13:52
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants