|
1 | 1 | import { Schema, Document, Model, Types, connection, model } from 'mongoose'; |
2 | 2 | import { expectError, expectType } from 'tsd'; |
3 | | -import { M0_0aAutoTypedSchemaType, autoTypedSchema } from './schema.test'; |
| 3 | +import { AutoTypedSchemaType, autoTypedSchema } from './schema.test'; |
4 | 4 |
|
5 | 5 | function conventionalSyntax(): void { |
6 | 6 | interface ITest extends Document { |
@@ -219,31 +219,26 @@ export function autoTypedModel() { |
219 | 219 | const AutoTypedModel = model('AutoTypeModel', AutoTypedSchema); |
220 | 220 |
|
221 | 221 | (async() => { |
222 | | - /* -------------------------------------------------------------------------- */ |
223 | | - /* Model-functions-test */ |
224 | | - /* -------------------------------------------------------------------------- */ |
| 222 | + // Model-functions-test |
225 | 223 | // Create should works with arbitrary objects. |
226 | 224 | const randomObject = await AutoTypedModel.create({ unExistKey: 'unExistKey', description: 'st' }); |
227 | 225 | expectType<string>(randomObject.unExistKey); |
228 | | - expectType<M0_0aAutoTypedSchemaType['schema']['userName']>(randomObject.userName); |
| 226 | + expectType<AutoTypedSchemaType['schema']['userName']>(randomObject.userName); |
229 | 227 |
|
230 | 228 | const testDoc1 = await AutoTypedModel.create({ userName: 'M0_0a' }); |
231 | | - expectType<M0_0aAutoTypedSchemaType['schema']['userName']>(testDoc1.userName); |
232 | | - expectType<M0_0aAutoTypedSchemaType['schema']['description']>(testDoc1.description); |
| 229 | + expectType<AutoTypedSchemaType['schema']['userName']>(testDoc1.userName); |
| 230 | + expectType<AutoTypedSchemaType['schema']['description']>(testDoc1.description); |
233 | 231 |
|
234 | 232 | const testDoc2 = await AutoTypedModel.insertMany([{ userName: 'M0_0a' }]); |
235 | | - expectType<M0_0aAutoTypedSchemaType['schema']['userName']>(testDoc2[0].userName); |
236 | | - expectType<M0_0aAutoTypedSchemaType['schema']['description'] | undefined>(testDoc2[0]?.description); |
| 233 | + expectType<AutoTypedSchemaType['schema']['userName']>(testDoc2[0].userName); |
| 234 | + expectType<AutoTypedSchemaType['schema']['description'] | undefined>(testDoc2[0]?.description); |
237 | 235 |
|
238 | 236 | const testDoc3 = await AutoTypedModel.findOne({ userName: 'M0_0a' }); |
239 | | - expectType<M0_0aAutoTypedSchemaType['schema']['userName'] | undefined>(testDoc3?.userName); |
240 | | - expectType<M0_0aAutoTypedSchemaType['schema']['description'] | undefined>(testDoc3?.description); |
| 237 | + expectType<AutoTypedSchemaType['schema']['userName'] | undefined>(testDoc3?.userName); |
| 238 | + expectType<AutoTypedSchemaType['schema']['description'] | undefined>(testDoc3?.description); |
241 | 239 |
|
242 | | - /* -------------------------------------------------------------------------- */ |
243 | | - /* Model-statics-functions-test */ |
244 | | - /* -------------------------------------------------------------------------- */ |
245 | | - |
246 | | - expectType<ReturnType<M0_0aAutoTypedSchemaType['statics']['staticFn']>>(AutoTypedModel.staticFn()); |
| 240 | + // Model-statics-functions-test |
| 241 | + expectType<ReturnType<AutoTypedSchemaType['statics']['staticFn']>>(AutoTypedModel.staticFn()); |
247 | 242 |
|
248 | 243 | })(); |
249 | 244 | return AutoTypedModel; |
|
0 commit comments