Typescript: Type metadata lost in mapped types

Created on 30 Jan 2018  路  4Comments  路  Source: microsoft/TypeScript

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: [email protected]


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:

Bug

Most helpful comment

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.

All 4 comments

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.

@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?

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

Screenshot:
image

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

CyrusNajmabadi picture CyrusNajmabadi  路  3Comments

blendsdk picture blendsdk  路  3Comments

Antony-Jones picture Antony-Jones  路  3Comments

dlaberge picture dlaberge  路  3Comments

weswigham picture weswigham  路  3Comments