Closed benschac closed 7 months ago
I dont understand this issue fully. Why can you not use the class as a type?
Class is a value. Type is a type.
Values can be inferred into types
When providing an sdk, we should provide all types a dev would need. Not make them infer types and guess around.
import Entropy from '@entropyxyz/entropy-js'
import type EntropyType from '@entropyxyz/entropy-js'
should be
import Entropy, type {
Entropy as EntropyType
} from '@entropyxyz/entropy-js'
making devs have to import the module twice is what should be avoided.
If I'm doing something wrong plz update the docs, and I'll give it another shot. tyty
why does this not work?
const entropy: Entropy = new Entropy(opts)
is there a pattern you are expecting not handled by the docs in typescript? https://www.typescriptlang.org/docs/handbook/2/classes.html
if you are unsatisfied with this pattern please open a PR with proposal pattern.
why does this not work?
const entropy: Entropy = new Entropy(opts)
Typescript doesn't know which is a value, and which is a type because they're both Entropy
if you are unsatisfied with this pattern please open a PR with proposal pattern.
Not sure its satisfied thing. A developer is going to have to do something like:
const entropy = new Entropy()
const EntropyType = typeof entropy
// or
const EntropyType = ReturnType<() => Entropy>
which could be handled if we export a type for a developer to use.
Not really the end of the world or anything. Just, a quick developer experience win.
But, can happily add a PR.
done
Currently need to:
Just looking through the
dist
in theentropy-client
project.there isn't an
Entropy
type exported, and the class is exported as a default, which thenew Entropy
object is also exposed as.doing a named export instead of a default export might help solve this issue.