Skip to content

Commit

Permalink
feat: use type instead of interface (#698)
Browse files Browse the repository at this point in the history
  • Loading branch information
FredyC committed May 25, 2020
1 parent 10addfa commit 4502fc9
Show file tree
Hide file tree
Showing 14 changed files with 66 additions and 29 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Expand Up @@ -3,3 +3,4 @@
**/fixtures/*
**/locale/*
docs/*
README.md
6 changes: 4 additions & 2 deletions .eslintrc
Expand Up @@ -2,6 +2,7 @@
"env": {
"jest/globals": true
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module",
Expand All @@ -10,7 +11,7 @@
}
},
"extends": ["plugin:import/errors", "plugin:import/warnings"],
"plugins": ["promise", "import", "react", "jest"],
"plugins": ["promise", "import", "react", "jest", "@typescript-eslint"],
"settings": {
"import/extensions": [".js", ".jsx", ".ts", ".tsx"],
"import/parsers": {
Expand All @@ -24,6 +25,7 @@
},
"rules": {
"no-duplicate-imports": "off",
"react/display-name": "off"
"react/display-name": "off",
"@typescript-eslint/consistent-type-definitions": ["error", "type"]
}
}
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -13,7 +13,7 @@
"watch": "cross-env NODE_ICU_DATA=node_modules/full-icu jest -c scripts/jest/config.unit.js --watch",
"watch:integration": "cross-env NODE_ICU_DATA=node_modules/full-icu jest -c scripts/jest/config.integration.js --watch",
"lint:types": "tsc",
"lint:eslint": "eslint packages/",
"lint:eslint": "eslint packages/**",
"lint": "yarn lint:eslint; yarn lint:types",
"release": "node ./scripts/release.js",
"release:integration": "node ./scripts/integration.js",
Expand All @@ -36,6 +36,7 @@
"@types/jest": "^25.2.1",
"@types/ramda": "^0.27.3",
"@types/react": "^16.9.34",
"@typescript-eslint/eslint-plugin": "^2.28.0",
"@typescript-eslint/parser": "^2.28.0",
"babel-code-frame": "^6.26.0",
"babel-core": "7.0.0-bridge.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/api/catalog.ts
Expand Up @@ -23,16 +23,16 @@ const NAME = "{name}"
const LOCALE = "{locale}"
const PATHSEP = "/" // force posix everywhere

export interface MakeOptions extends CliExtractOptions {
export type MakeOptions = CliExtractOptions & {
projectType?: string
orderBy?: OrderBy
}

export interface MergeOptions {
export type MergeOptions = {
overwrite: boolean
}

export interface GetTranslationsOptions {
export type GetTranslationsOptions = {
sourceLocale: string
fallbackLocale: string
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/api/compile.ts
Expand Up @@ -8,7 +8,7 @@ import pseudoLocalize from "./pseudoLocalize"

export type CompiledCatalogNamespace = "cjs" | "es" | string

export interface CreateCompileCatalogOptions {
export type CreateCompileCatalogOptions = {
strict?: boolean
namespace?: CompiledCatalogNamespace
pseudoLocale?: string
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/api/extractors/types.ts
Expand Up @@ -3,12 +3,12 @@ export type ExtractorType = {
extract(filename: string, targetDir: string, options?: ExtractOptions): void
}

export interface BabelOptions {
export type BabelOptions = {
plugins?: Array<string>
presets?: Array<string>
}

export interface ExtractOptions {
export type ExtractOptions = {
projectType?: string
babelOptions?: BabelOptions
}
4 changes: 2 additions & 2 deletions packages/cli/src/api/formats/index.ts
Expand Up @@ -6,12 +6,12 @@ import { CatalogType } from "../types"

const formats: { [key: string]: CatalogFormat } = { lingui, minimal, po, csv }

export interface CatalogFormatOptions {
export type CatalogFormatOptions = {
locale: string
origins: false
}

export interface CatalogFormat {
export type CatalogFormat = {
catalogExtension: string
write(
filename: string,
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/api/types.ts
Expand Up @@ -2,7 +2,7 @@ type Maybe<T> = T | null | undefined

export type IdempotentResult<T> = [boolean, Maybe<T>] // [ created, result ]

export interface ExtractedMessageType {
export type ExtractedMessageType = {
message?: string
origin: Array<[number, string]>
comment?: string
Expand All @@ -11,7 +11,7 @@ export interface ExtractedMessageType {
flags?: Array<string>
}

export interface MessageType extends ExtractedMessageType {
export type MessageType = ExtractedMessageType & {
translation: string
}

Expand Down
3 changes: 1 addition & 2 deletions packages/cli/src/lingui-extract.ts
@@ -1,8 +1,7 @@
import chalk from "chalk"
import program from "commander"

import { getConfig } from "@lingui/conf"
import { LinguiConfig } from "@lingui/conf"
import { getConfig, LinguiConfig } from "@lingui/conf"

import { getCatalogs } from "./api/catalog"

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/i18n.ts
Expand Up @@ -26,7 +26,7 @@ export type Messages = Record<string, CompiledMessage>

export type AllMessages = Record<Locale, Messages>

export interface MessageDescriptor {
export type MessageDescriptor = {
id?: string
comment?: string
message?: string
Expand Down
19 changes: 10 additions & 9 deletions packages/macro/index.d.ts
@@ -1,13 +1,13 @@
import { ComponentType, ReactNode } from "react"
import { MessageDescriptor } from "@lingui/core"
import { TransRenderType } from "@lingui/react"
import type { ComponentType, ReactNode } from "react"
import type { MessageDescriptor } from "@lingui/core"
import type { TransRenderType } from "@lingui/react"

export function t(
literals: TemplateStringsArray,
...placeholders: any[]
): string

export interface ChoiceOptions<T = string> {
export type ChoiceOptions<T = string> = {
offset?: number
zero?: T
one?: T
Expand All @@ -26,20 +26,21 @@ export function defineMessages<M extends Record<string, MessageDescriptor>>(
): M
export function defineMessage(descriptor: MessageDescriptor): MessageDescriptor

export interface TransProps {
export type TransProps = {
id?: string
comment?: string
render?: TransRenderType
}

export interface ChoiceProps extends TransProps, ChoiceOptions<ReactNode> {
export type ChoiceProps = {
value?: string | number
}
} & TransProps &
ChoiceOptions<ReactNode>

export interface SelectProps extends TransProps {
export type SelectProps = {
value?: string
other?: ReactNode
}
} & TransProps

export const Trans: ComponentType<TransProps>
export const Plural: ComponentType<ChoiceProps>
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/I18nProvider.tsx
Expand Up @@ -2,12 +2,12 @@ import React, { FunctionComponent } from "react"
import { I18n } from "@lingui/core"
import { TransRenderType } from "./Trans"

interface I18nContext {
type I18nContext = {
i18n: I18n
defaultRender?: TransRenderType
}

export interface I18nProviderProps extends I18nContext {}
export type I18nProviderProps = I18nContext

const LinguiContext = React.createContext<I18nContext>(null)

Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/Trans.tsx
Expand Up @@ -3,7 +3,7 @@ import React from "react"
import { useLingui } from "./I18nProvider"
import { formatElements } from "./format"

export interface TransRenderProps {
export type TransRenderProps = {
id: string
translation: React.ReactNode
message: string | null
Expand All @@ -14,7 +14,7 @@ export type TransRenderType =
| React.ElementType<TransRenderProps>
| React.ReactElement

export interface TransProps {
export type TransProps = {
id: string
message?: string
values: Object
Expand Down
33 changes: 33 additions & 0 deletions yarn.lock
Expand Up @@ -1537,6 +1537,16 @@
dependencies:
"@types/yargs-parser" "*"

"@typescript-eslint/eslint-plugin@^2.28.0":
version "2.33.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.33.0.tgz#d6c8319d5011b4783bb3d2dadf105d8bdd499bd5"
integrity sha512-QV6P32Btu1sCI/kTqjTNI/8OpCYyvlGjW5vD8MpTIg+HGE5S88HtT1G+880M4bXlvXj/NjsJJG0aGcVh0DdbeQ==
dependencies:
"@typescript-eslint/experimental-utils" "2.33.0"
functional-red-black-tree "^1.0.1"
regexpp "^3.0.0"
tsutils "^3.17.1"

"@typescript-eslint/experimental-utils@2.28.0", "@typescript-eslint/experimental-utils@^2.5.0":
version "2.28.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-2.28.0.tgz#1fd0961cd8ef6522687b4c562647da6e71f8833d"
Expand All @@ -1547,6 +1557,16 @@
eslint-scope "^5.0.0"
eslint-utils "^2.0.0"

"@typescript-eslint/experimental-utils@2.33.0":
version "2.33.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-2.33.0.tgz#000f1e5f344fbea1323dc91cc174805d75f99a03"
integrity sha512-qzPM2AuxtMrRq78LwyZa8Qn6gcY8obkIrBs1ehqmQADwkYzTE1Pb4y2W+U3rE/iFkSWcWHG2LS6MJfj6SmHApg==
dependencies:
"@types/json-schema" "^7.0.3"
"@typescript-eslint/typescript-estree" "2.33.0"
eslint-scope "^5.0.0"
eslint-utils "^2.0.0"

"@typescript-eslint/parser@^2.28.0":
version "2.28.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-2.28.0.tgz#bb761286efd2b0714761cab9d0ee5847cf080385"
Expand All @@ -1570,6 +1590,19 @@
semver "^6.3.0"
tsutils "^3.17.1"

"@typescript-eslint/typescript-estree@2.33.0":
version "2.33.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-2.33.0.tgz#33504c050ccafd38f397a645d4e9534d2eccbb5c"
integrity sha512-d8rY6/yUxb0+mEwTShCQF2zYQdLlqihukNfG9IUlLYz5y1CH6G/9XYbrxQLq3Z14RNvkCC6oe+OcFlyUpwUbkg==
dependencies:
debug "^4.1.1"
eslint-visitor-keys "^1.1.0"
glob "^7.1.6"
is-glob "^4.0.1"
lodash "^4.17.15"
semver "^7.3.2"
tsutils "^3.17.1"

"@webassemblyjs/ast@1.9.0":
version "1.9.0"
resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.9.0.tgz#bd850604b4042459a5a41cd7d338cbed695ed964"
Expand Down

1 comment on commit 4502fc9

@vercel
Copy link

@vercel vercel bot commented on 4502fc9 May 25, 2020

Choose a reason for hiding this comment

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

Deployment failed with the following error:

request to https://api.vercel.com/v10/now/deployments?teamId=team_fbTCV1mi6FskDB6Tzea5F5ao&skipAutoDetectionConfirmation=1 failed, reason: socket hang up

Please sign in to comment.