Example from readme with typescript
kevinsimper opened this issue · 5 comments
kevinsimper commented
I tried the example and it does not seem to compile
import Conf from 'conf'
const schema = {
bar: {
type: 'string'
}
};
const config = new Conf({schema});
https://repl.it/repls/AliveLumberingTechnicians#index.ts
/usr/local/lib/node_modules/ts-node-fm/src/index.ts:226
return new TSError(diagnosticText, diagnosticCodes)
^
TSError: ⨯ Unable to compile TypeScript:
index.ts:9:25 - error TS2345: Argument of type '{ schema: { bar: { type: string; }; }; }' is not assignable to parameter of type 'Readonly<Partial<Options<{ bar: {}; }>>>'.
Types of property 'schema' are incompatible.
Type '{ bar: { type: string; }; }' is not assignable to type 'Schema<{ bar: {}; }>'.
Types of property 'bar' are incompatible.
Type '{ type: string; }' is not assignable to type 'JSONSchema'.
Types of property 'type' are incompatible.
Type 'string' is not assignable to type '"string" | "number" | "boolean" | "object" | JSONSchemaType | "array" | "integer" | "null" | ("string" | "number" | "boolean" | "object" | JSONSchemaType | "array" | "integer" | "null")[] | undefined'.
9 const config = new Conf({schema});
~~~~~~~~
at createTSError (/usr/local/lib/node_modules/ts-node-fm/src/index.ts:226:12)
at getOutput (/usr/local/lib/node_modules/ts-node-fm/src/index.ts:335:40)
at Object.compile (/usr/local/lib/node_modules/ts-node-fm/src/index.ts:368:11)
at startRepl (/usr/local/lib/node_modules/ts-node-fm/src/bin.ts:147:28)
at Object.<anonymous> (/usr/local/lib/node_modules/ts-node-fm/src/bin.ts:66:1)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
sindresorhus commented
Can you reproduce this with the latest TypeScript version?
We have a type test for this:
Lines 35 to 56 in 1dcfd0d
kevinsimper commented
@sindresorhus I clone the repo and it is appearently down to how you define the schema, I am really confused: #121
The same error here: https://travis-ci.com/github/sindresorhus/conf/jobs/370496506
sneljo1 commented
Located the issue, we expected the schema to by typed like const schema: Schema<UnicornFoo>
, but we should also allow standard objects for people who do not want to explicitly type it.
SnosMe commented
kevinsimper commented
Some good solutions has come up 👍