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

Type metadata lost in mapped types #21489

Closed
NicholasBoll opened this issue Jan 30, 2018 · 4 comments
Closed

Type metadata lost in mapped types #21489

NicholasBoll opened this issue Jan 30, 2018 · 4 comments
Labels
Bug A bug in TypeScript
Milestone

Comments

@NicholasBoll
Copy link

We are using typedoc and noticed type metadata that drives the docs is lost when mapped types are used. It may be possible for mapped types to invalidate metadata (maybe @example for instance). Metadata like description should still hold true from a mapped type.

Maybe this is an intentional design choice, but it seems in many cases this metadata can be very useful even if passed through mapped types. Many libraries use mapped types like Pick or Omit which don't actually change metadata relevance.

TypeScript Version: typescript@2.8.0-dev.20180130

Search Terms:
pick mapped types
mapped types jsdoc
jsdoc mapped
jsdoc types
mapped types meta
mapped types meta data

Code

interface Foo {
  /** some doc */
  bar: string
}

const foo: Foo = {
  bar: 'baz'
}

foo.bar // description: "some doc" 

type Foo2 = Pick<Foo, 'bar'>

const foo2: Foo2 = {
  bar: 'baz'
}

foo2.bar // description lost

Expected behavior:
Type metadata follows the result of mapped types

Actual behavior:
All metadata is lost

Playground Link:
You'll have to put the cursor on the bar of foo.bar and hit Ctrl+Space to see the Intellisense
https://www.typescriptlang.org/play/#src=interface%20Foo%20%7B%0D%0A%20%20%2F**%20some%20doc%20*%2F%0D%0A%20%20bar%3A%20string%0D%0A%7D%0D%0A%0D%0Aconst%20foo%3A%20Foo%20%3D%20%7B%0D%0A%20%20bar%3A%20'baz'%0D%0A%7D%0D%0A%0D%0Afoo.bar%20%2F%2F%20description%3A%20%22some%20doc%22%20%0D%0A%0D%0Atype%20Foo2%20%3D%20Pick%3CFoo%2C%20'bar'%3E%0D%0A%0D%0Aconst%20foo2%3A%20Foo2%20%3D%20%7B%0D%0A%20%20bar%3A%20'baz'%0D%0A%7D%0D%0A%0D%0Afoo2.bar%20%2F%2F%20description%20lost

Related Issues:

@mhegazy
Copy link
Contributor

mhegazy commented Jan 30, 2018

Pick destructures the type into a list of names, and a list of property types, with this it makes it hard for the compiler to track them back to their original declaration. but we should be able to copy the comments as we create a new symbol.

@mhegazy mhegazy added the Bug A bug in TypeScript label Jan 30, 2018
@mhegazy mhegazy added this to the TypeScript 2.8 milestone Jan 30, 2018
@mhegazy mhegazy modified the milestones: TypeScript 2.8, TypeScript 2.9 Mar 9, 2018
@TedDriggs
Copy link

TedDriggs commented May 7, 2018

@bterlson this looks to be the issue that we discussed at Build today.

@mhegazy would this also cause JSX expression attributes to not get JSDocs?

@iansan5653
Copy link

This appears to be fixed, at least since version 3.1.6: demo

Screenshot:
image

@NicholasBoll
Copy link
Author

It does seem like this issue is fixed! Maybe by accident or part of some other work.

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

No branches or pull requests

6 participants