Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No return type validation for function that returns mapped object with template literals as keys #47289

Closed
kbialowas opened this issue Jan 2, 2022 · 1 comment

Comments

@kbialowas
Copy link

kbialowas commented Jan 2, 2022

Bug Report

🔎 Search Terms

"return type validation"
"mapped type resolved to any"
"template literals"

🕗 Version & Regression Information

Happens on every version I tried since 4.1.5 (previous versions says, that operator 'as' isn't available).

⏯ Playground Link

Playground link with relevant code

💻 Code

type MappedKeys<T extends string, TBase={bar: unknown, baz: unknown}> = {
    [key in keyof TBase as `${T}_${string & key}`]: number
}
function mapKeys<T extends string>(prefix: T): MappedKeys<T> {
    return "No type controll :("
}
const a = mapKeys("foo");
a.foo_bar

🙁 Actual behavior

Typescript shows no error for mapKeys function return type.

Typing a. suggests that a is an object and has two fields - a.foo_bar and a.foo_baz.

Screenshot 2022-01-02 at 18 09 17

🙂 Expected behavior

Typescript compiler should show error when returned type isn't matching declared return type.

@kbialowas
Copy link
Author

I guess it's related to limitations mentioned here:

#23918
#23433

When I remove generic prefix, checks work fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant