Skip to content

etcd/tsc-arrow-fn-declarations-bug

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bug repro: tsc incorrectly simplifies arrow function types

tsc incorrectly simplifies declaration types for functions written in arrow notation. The tsc command used to build the source is as follows:

tsc src/*.ts --outdir build/ --allowSyntheticDefaultImports --declaration --sourceMap

And the source, containing equivalent functions aside from notation, is as follows:

export const map = <I, O>(i: I | undefined, fn: (_: I) => O): O | undefined => {
  if (i === undefined) {
    return undefined;
  }

  return fn(i);
};

export function map2<I, O>(i: I | undefined, fn: (_: I) => O): O | undefined {
  if (i === undefined) {
    return undefined;
  }

  return fn(i);
}

But tsc generates the following types:

export declare const map: <I, O>(i: I, fn: (_: I) => O) => O;

export declare function map2<I, O>(
  i: I | undefined,
  fn: (_: I) => O
): O | undefined;

As seen above, map has an incorrect type signature, while map2 has the correct type signature.

Commands to reproduce bug using this repo

# install `typescript` dependency
npm install

# clear the old build
rm -rf build

# run build
npm run build

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published