diff --git a/test/types/enum.test-d.ts b/test/types/enum.test-d.ts new file mode 100644 index 0000000000..225282f618 --- /dev/null +++ b/test/types/enum.test-d.ts @@ -0,0 +1,47 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +import { expectAssignable, expectType } from 'tsd'; + +import { + AuthMechanism, + AutoEncryptionLoggerLevel, + BatchType, + BSONType, + Compressor, + CURSOR_FLAGS, + CursorFlag, + ExplainVerbosity, + GSSAPICanonicalizationValue, + LoggerLevel, + ProfilingLevel, + ReadConcernLevel, + ReadPreferenceMode, + ReturnDocument, + ServerApiVersion, + ServerType, + TopologyType +} from '../../src/index'; + +const num: number = Math.random(); + +// In our index.ts we clump CURSOR_FLAGS with the enums but its an array +expectType(CURSOR_FLAGS[num]); + +// Explain is kept as type string so we can automatically allow any new level to be passed through +expectAssignable(Object.values(ExplainVerbosity)[num]); + +// Note both the Enum name and a property on the enum are the same type +// Object.values(x)[num] gets a union of the all the value types +expectType(Object.values(AuthMechanism)[num]); +expectType(Object.values(AutoEncryptionLoggerLevel)[num]); +expectType(Object.values(BatchType)[num]); +expectType(Object.values(BSONType)[num]); +expectType(Object.values(Compressor)[num]); +expectType(Object.values(GSSAPICanonicalizationValue)[num]); +expectType(Object.values(LoggerLevel)[num]); +expectType(Object.values(ProfilingLevel)[num]); +expectType(Object.values(ReadConcernLevel)[num]); +expectType(Object.values(ReadPreferenceMode)[num]); +expectType(Object.values(ReturnDocument)[num]); +expectType(Object.values(ServerApiVersion)[num]); +expectType(Object.values(ServerType)[num]); +expectType(Object.values(TopologyType)[num]);