Force interface instead of type for better docs (#3815)

Typescript's type aliases (`type X = thing`) can refer to basically
anything, which makes it hard to write an automatic document formatter
for them. Interfaces on the other hand are only object, so they play
much nicer with docs. Currently, object-flavoured type aliases don't
really get expanded at all on our docs site, which means we have a bunch
of docs content that's not shown on the site.

This diff introduces a lint rule that forces `interface X {foo: bar}`s
instead of `type X = {foo: bar}` where possible, as it results in a much
better documentation experience:

Before:
<img width="437" alt="Screenshot 2024-05-22 at 15 24 13"
src="https://github.com/tldraw/tldraw/assets/1489520/32606fd1-6832-4a1e-aa5f-f0534d160c92">

After:
<img width="431" alt="Screenshot 2024-05-22 at 15 33 01"
src="https://github.com/tldraw/tldraw/assets/1489520/4e0d59ee-c38e-4056-b9fd-6a7f15d28f0f">


### Change Type

- [x] `sdk` — Changes the tldraw SDK
- [x] `docs` — Changes to the documentation, examples, or templates.
- [x] `improvement` — Improving existing features
This commit is contained in:
alex 2024-05-22 16:55:49 +01:00 committed by GitHub
parent abc8521a71
commit f9ed1bf2c9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
131 changed files with 731 additions and 434 deletions

View file

@ -1,7 +1,7 @@
import { execFile } from 'child_process'
import { nicelog } from './nicelog'
type ExecOpts = {
interface ExecOpts {
pwd?: string
processStdoutLine?: (line: string) => void
processStderrLine?: (line: string) => void

View file

@ -1,7 +1,7 @@
import { join } from 'path'
import { REPO_ROOT, writeJsonFile } from './file'
type Label = {
interface Label {
// this is what the label is 'called' on github
name: string
// this is how we describe the label in our pull request template

View file

@ -8,7 +8,7 @@ import { REPO_ROOT } from './file'
import { nicelog } from './nicelog'
import { getAllWorkspacePackages } from './workspace'
export type PackageDetails = {
export interface PackageDetails {
name: string
dir: string
localDeps: string[]

View file

@ -6,7 +6,7 @@ export type PackageJson = { name: string; private?: boolean; workspaces?: string
string,
any
>
export type Package = {
export interface Package {
packageJson: PackageJson
relativePath: string
path: string

View file

@ -6,7 +6,7 @@ import { nicelog } from './lib/nicelog'
// `env` instead. This makes sure that all required env vars are present.
const env = makeEnv(['CLOUDFLARE_ACCOUNT_ID', 'CLOUDFLARE_API_TOKEN', 'GH_TOKEN'])
type ListWorkersResult = {
interface ListWorkersResult {
success: boolean
result: { id: string }[]
}

View file

@ -215,7 +215,10 @@ async function copyTranslations() {
// languages.ts
const languagesSource = await readJsonIfExists(join(sourceFolderPath, 'languages.json'))!
type Language = { label: string; locale: string }
interface Language {
label: string
locale: string
}
const languagesFile = `
/** @public */
export const LANGUAGES = ${JSON.stringify(