Skip to content

Error with multiple templates as indexes #50220

@jer-sen

Description

@jer-sen

Bug Report

I'm have some issues with the last version of MongoDB node.js driver. There is now a type check on the queries filter/update (which is really great!) but some complex types require to bypass it..
Cf mongodb/node-mongodb-native#3328

🔎 Search Terms

record object template index indexes key

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about common bugs that aren't bugs

⏯ Playground Link

https://www.typescriptlang.org/play?ts=4.8.0-dev.20220808#code/MYewdgzgLgBCCMAuGBvGBtA1kmADAhgHQAkKYArgLYBGApgE4C+uAuslPebTIzALyoMBEigAi+KLUJgQAdwAUASmZsYHLjxj4IMUJCgBuAFAB6E-wB8MAHIgYDeiHpGje6HABMyNFhzDSFDQMKuyc3LwCPv5iElIyCsqsoRqMxmaWMAAqAJ4ADtwA5D4AHsjQ9ACWYADmqtQgIAA2tPhgBjwFMBU6MrDaEBXVYPjUzWp2UHmFPtjI0YF0TElqYe2MBYQubrAgAMzeGLN4RAFUiyErXAA0h1541CILwcsAZviNEOH8gujR4pLSORKC7qWg3AoPAAMBWQbw+X20unA0DS5j4Vhy+RgRRg9BaABNwI1shhSjBylVash6k0Wm1cQSiSSIYRobD3p81p1ujBeloIAMhiMxlAJlNsTM-CcyGdnqpQe0sHdcA9TkElqo4ZyOptXMidgAWA6+ObSp4a5Jg25zVUy9UXLVfSJCaX-OJAxLysLgqEwmCOniojKY6aksocSl1BrNVrtFls-0c2hcro9EB9AWDYajbiitTinEm46PWUWy7J633Ev215JrmbIA

💻 Code

const o1: { [k1: `a.${number}`]: true } = { [`a.${Date.now()}`]: true } as const;
// => No error

const o2: { [k1: `a.${number}`]: true } = { [`a.${Date.now()}`]: true };
// => Type '{ [x: string]: boolean; }' is not assignable to type '{ [k1: `a.${number}`]: true; }'.

const o3: { [k1: `a.${number}`]: true, [k2: `b.${number}`]: false } = { [`a.${Date.now()}`]: true, 'b.0': false } as const;
// => Type '{ readonly [x: string]: boolean; readonly 'b.0': false; }' is not assignable to type '{ [k1: `a.${number}`]: true; [k2: `b.${number}`]: false; }'.

const o4: { [k1: `a.${number}`]: true, [k2: `b.${number}`]: false } = { [`a.${Date.now()}`]: true, 'b.0': false };
// => Type '{ [x: string]: boolean; 'b.0': false; }' is not assignable to type '{ [k1: `a.${number}`]: true; [k2: `b.${number}`]: false; }'.

🙁 Actual behavior

Errors with o3 and o4 declarations. I think o2 should work also.

🙂 Expected behavior

No errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions