-
-
Notifications
You must be signed in to change notification settings - Fork 590
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
Fix type errors in README.md #3766
Conversation
Most examples in the README have type errors have type errors when using `"matrix-js-sdk": "^28.2.0"`. There are several causes: * Passing plain strings (e.g. `"Room.timeline"`) as event names does not type-check, because the event names are defined using a TypeScript `enum`. Instead, one must use `sdk.RoomEvent.Timeline` etc. * The examples imply callback-based APIs that seem to no longer exist. For example, `client.publicRooms` does not take a callback; instead it returns a `Promise`. * The examples assume some values that, according to the types, can be `null` or `undefined`. * The examples use some accessors like `client.store.rooms` that do not exist in the types; instead one must use getters like `client.store.getRooms()`.
The examples are JS rather than TS where the strings continue to work just fine |
My assumption is that you want JS that is not just runtime-correct, but also type-correct according to your own typings. If they're not, most people trying to get started will assume (as I did) that the code is broken. (I believe even the developers writing JS will be using the TypeScript typings, because IDEs use these published typings even in JS.) The approach I took is to fix the examples to work with the typings. The alternative is to fix the types to work with the examples. The problem is that matrix-js-sdk is using TypeScript's For example, this is how export enum ClientEvent {
Sync = "sync",
Event = "event",
// ...
TurnServers = "turnServers",
TurnServersError = "turnServers.error",
} Using this definition, this does not type-check: // Error: Type '"sync"' is not assignable to type 'ClientEvent'
const ev: sdk.ClientEvent = "sync"; If you want this to work, a better definition would be: export const ClientEvent = {
Sync: "sync",
Event: "event",
// ...
TurnServers: "turnServers",
TurnServersError: "turnServers.error",
} as const;
export type ClientEvent = typeof ClientEvent[keyof typeof ClientEvent]; // "sync" | "event" | ... So - do the team instead want to fix the types to work with the examples? |
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.
Looks sane, thanks
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.
@jameshfisher the linter isn't happy with you, please fix it and request a re-review
closing this as it seems to have bitrotted. |
Pull request was closed
Most examples in the README have type errors have type errors when using
"matrix-js-sdk": "^28.2.0"
. There are several causes:"Room.timeline"
) as event names does not type-check, because the event names are defined using a TypeScriptenum
. Instead, one must usesdk.RoomEvent.Timeline
etc.client.publicRooms
does not take a callback; instead it returns aPromise
.null
orundefined
.client.store.rooms
that do not exist in the types; instead one must use getters likeclient.store.getRooms()
.Checklist
This change is marked as an internal change (Task), so will not be included in the changelog.