Skip to content

Commit 0819886

Browse files
authored
refactor: enable strictNullChecks in conf package (#2334)
1 parent 25303c2 commit 0819886

File tree

6 files changed

+18
-12
lines changed

6 files changed

+18
-12
lines changed

packages/cli/src/api/catalog/getFallbackListForLocale.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ export function getFallbackListForLocale(
1111
Array.isArray(mapping) ? fL.push(...mapping) : fL.push(mapping)
1212
}
1313

14-
if (fallbackLocales?.default && locale !== fallbackLocales?.default) {
15-
fL.push(fallbackLocales?.default)
14+
if (
15+
typeof fallbackLocales?.default === "string" &&
16+
locale !== fallbackLocales?.default
17+
) {
18+
fL.push(fallbackLocales.default)
1619
}
1720

1821
return fL

packages/conf/src/getConfig.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { makeConfig } from "./makeConfig"
66
import { createJiti } from "jiti"
77
import pico from "picocolors"
88

9-
function configExists(path: string) {
10-
return path && fs.existsSync(path)
9+
function configExists(path?: string): path is string {
10+
return !!path && fs.existsSync(path)
1111
}
1212

1313
function JitiLoader(): LoaderSync {

packages/conf/src/migrations/setCldrParentLocales.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export function setCldrParentLocales(
1010
} as unknown as LinguiConfigNormalized
1111
}
1212

13-
if (!config.fallbackLocales.default) {
13+
if (!config.fallbackLocales?.default) {
1414
config.locales.forEach((locale) => {
1515
const fl = getCldrParentLocale(locale.toLowerCase())
1616
if (fl && !(config.fallbackLocales as FallbackLocales)[locale]) {

packages/conf/src/types.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,11 @@ export type CatalogConfig = {
106106
exclude?: string[]
107107
}
108108

109-
type LocaleObject = {
110-
[locale: string]: string[] | string
111-
default?: string
112-
}
109+
type LocaleObject =
110+
| Record<string, string[] | string>
111+
| (Record<string, string[] | string> & {
112+
default: string
113+
})
113114

114115
export type FallbackLocales = LocaleObject
115116

@@ -257,7 +258,7 @@ export type LinguiConfig = {
257258
*
258259
* Note that using <rootDir> as a string token in any other path-based config settings will refer back to this value.
259260
*
260-
* @defaul: The root of the directory containing your Lingui configuration file or the package.json.
261+
* @default: The root of the directory containing your Lingui configuration file or the package.json.
261262
*/
262263
rootDir?: string
263264
/**

packages/conf/src/utils/replaceRootDir.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ import { LinguiConfig } from "../types"
22

33
export function replaceRootDir<T extends Partial<LinguiConfig>>(
44
config: T,
5-
rootDir: string
5+
rootDir: string | undefined
66
): T {
7+
if (!rootDir) {
8+
return config
9+
}
710
return (function replaceDeep(value: any, rootDir: string): any {
811
const replace = (s: string) => s.replace("<rootDir>", rootDir)
912

packages/conf/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"resolveJsonModule": true,
1111
"skipLibCheck": true,
1212
"strict": true,
13-
"strictNullChecks": false
1413
},
1514
"files": [
1615
"./src/index.ts"

0 commit comments

Comments
 (0)