Skip to content

Commit 72e87df

Browse files
committed
Add strict types
1 parent fa0df17 commit 72e87df

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export function toJson(value, options = {}) {
2424
const comments = comment ? (Array.isArray(comment) ? comment : [comment]) : []
2525
const delimiter = options.delimiter || ':'
2626
const forgiving = options.forgiving
27+
/** @type {Record<string, unknown>} */
2728
const propertyOrValues = {}
2829

2930
const lines = value
@@ -46,6 +47,7 @@ export function toJson(value, options = {}) {
4647
// Transform `value` to a property--value tuple.
4748
function (value) {
4849
const values = value.split(delimiter)
50+
// @ts-expect-error: always one.
4951
const result = [values.shift().trim()]
5052

5153
if (values.length > 0) {
@@ -56,7 +58,7 @@ export function toJson(value, options = {}) {
5658
}
5759
)
5860

59-
/** @type {boolean} */
61+
/** @type {boolean|undefined} */
6062
let isPropertyValuePair
6163

6264
for (const [index, line] of pairs.entries()) {
@@ -126,5 +128,6 @@ export function toJson(value, options = {}) {
126128
* @param {Array<string>} b
127129
*/
128130
function sortOnFirstIndex(a, b) {
131+
// @ts-expect-error: never empty
129132
return a[0].codePointAt(0) - b[0].codePointAt(0)
130133
}

test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ test('Invalid lists', function (t) {
173173

174174
t.test('should honour `log: false`', function (st) {
175175
const stop = cept(console, 'log', hoist)
176-
/** @type {Array<unknown>} */
176+
/** @type {Array<unknown>|undefined} */
177177
let parameters
178178

179179
toJson('unicorn\nrainbow\nunicorn', {forgiving: true, log: false})
@@ -229,7 +229,7 @@ test('Invalid objects', function (t) {
229229

230230
t.test('should honour `log: false`', function (st) {
231231
const stop = cept(console, 'log', hoist)
232-
/** @type {Array<unknown>} */
232+
/** @type {Array<unknown>|undefined} */
233233
let parameters
234234

235235
toJson('doge: so scare\nunicorn: magic creature\ndoge: so scare\n', {

tsconfig.json

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
{
2-
"include": ["*.js"],
2+
"include": ["**/**.js"],
3+
"exclude": ["coverage", "node_modules"],
34
"compilerOptions": {
4-
"target": "ES2020",
5-
"lib": ["ES2020"],
6-
"module": "ES2020",
7-
"moduleResolution": "node",
8-
"allowJs": true,
95
"checkJs": true,
106
"declaration": true,
117
"emitDeclarationOnly": true,
12-
"allowSyntheticDefaultImports": true,
13-
"skipLibCheck": true
8+
"exactOptionalPropertyTypes": true,
9+
"forceConsistentCasingInFileNames": true,
10+
"lib": ["es2020"],
11+
"module": "node16",
12+
"newLine": "lf",
13+
"skipLibCheck": true,
14+
"strict": true,
15+
"target": "es2020"
1416
}
1517
}

0 commit comments

Comments
 (0)