Skip to content

Commit

Permalink
turn on most of "strict": true
Browse files Browse the repository at this point in the history
  • Loading branch information
mmkal committed Sep 6, 2024
1 parent 22b91c7 commit 67f5348
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/typegen/src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export const generate = async (inputOptions: Partial<Options>) => {
const content = new Map<string, string>()
const promises: Array<Promise<void>> = []
const getContentSync = (filepath: string) => fs.readFileSync(filepath).toString()
const handler = async (filepath: string, ...args) => {
const handler = async (filepath: string, ...args: unknown[]) => {
const fullpath = path.join(cwd, filepath)
// eslint-disable-next-line @typescript-eslint/no-var-requires
logger.info(require('util').inspect({filepath, fullpath, args}))
Expand Down
8 changes: 5 additions & 3 deletions packages/typegen/src/type-parsers/map-type-parser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {ParseFn, pgTypes, setRecommendedTypeParsers} from '@pgkit/client'
import * as assert from 'assert'
import {TypeParserInfo} from '../types'

const jsValueMatchers: Array<[type: string, test: (value: unknown) => boolean]> = [
Expand All @@ -15,7 +16,7 @@ const jsValueMatchers: Array<[type: string, test: (value: unknown) => boolean]>
// todo: explicitly test to see how these all come back by default from pg
// e.g. by doing sql`select ${sampleValue}::${sampleValueType}` somehow
// but wait - should these all be strings?
export const sampleTypeValues: Record<string, any> = {
export const sampleTypeValues: Record<string, string | number> = {
int8: 0,
date: '2000-01-01',
interval: '1 hour',
Expand All @@ -34,7 +35,7 @@ export const sampleTypeValues: Record<string, any> = {
}

export const inferTypeParserTypeScript = (tp: ParseFn, defaultSampleInput = ''): string => {
const sample = tp(sampleTypeValues[tp.name] || defaultSampleInput)
const sample: unknown = tp((sampleTypeValues[tp.name] as string) || defaultSampleInput)
const match = jsValueMatchers.find(m => m[1](sample))
return match?.[0] || `unknown`
}
Expand All @@ -44,7 +45,8 @@ export const defaultTypeParsers = (setTypeParsers = setRecommendedTypeParsers):
setTypeParsers({
builtins: pgTypes.builtins,
setTypeParser(typeId, parse) {
list.push({oid: typeId, typescript: inferTypeParserTypeScript(parse)})
assert.ok(typeof parse === 'function', `Expected parse to be a function, got ${typeof parse}`)
list.push({oid: typeId, typescript: inferTypeParserTypeScript(ts => parse(ts))})
},
})
return list
Expand Down
5 changes: 2 additions & 3 deletions packages/typegen/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
"target": "ES2022",
"module": "NodeNext",
"jsx": "preserve",
"strict": false,
"strictNullChecks": true,
"strict": true,
"strictFunctionTypes": false,
"noEmit": true,
"noUncheckedIndexedAccess": false,
"noErrorTruncation": true,
"esModuleInterop": true
},
Expand Down

0 comments on commit 67f5348

Please sign in to comment.