Git Product home page Git Product logo

dts-emit-widened-unwidened-examples's Introduction

dts-emit-widened-unwidened-examples

$ npx tsc     # Emit using current rules

$ rm src/a.ts # Simulate using d.ts files externally or via project references
$ npx tsc
$ git diff src/*d.ts

Gives:

diff --git a/src/b.d.ts b/src/b.d.ts
index 7978d2c..b92a151 100644
--- a/src/b.d.ts
+++ b/src/b.d.ts
@@ -2,7 +2,7 @@ export declare const constFromConst: string;
 export declare let letFromConst: string;
 export declare const constFromLet: string;
 export declare let letFromLet: string;
-export declare function returnConstValue(): "foo" | "bar";
+export declare function returnConstValue(): string;
 export declare const constY: number;
 export declare let letY: number;
-export declare function returnY(): 1 | 0;
+export declare function returnY(): number;

Meaning we used to observe the unwidened values from a.ts, but now we observe the widened values from a.d.ts.

Now, running with microsoft/TypeScript#55445 which doesn't widen in d.ts emit:

$ tsc
$ git diff src/*.d.ts
diff --git a/src/a.d.ts b/src/a.d.ts
index e38d94a..7321615 100644
--- a/src/a.d.ts
+++ b/src/a.d.ts
@@ -1,6 +1,6 @@
-export declare const constValue: string;
+export declare const constValue: "foo" | "bar";
 export declare let letValue: string;
 export declare function returnConstValue(): "foo" | "bar";
 export declare const indirect: "foo" | "bar";
-export declare const y: number;
+export declare const y: 1 | 0;
 export declare function returnY(): 1 | 0;
diff --git a/src/b.d.ts b/src/b.d.ts
index 7978d2c..a79657f 100644
--- a/src/b.d.ts
+++ b/src/b.d.ts
@@ -1,8 +1,8 @@
-export declare const constFromConst: string;
+export declare const constFromConst: "foo" | "bar";
 export declare let letFromConst: string;
 export declare const constFromLet: string;
 export declare let letFromLet: string;
 export declare function returnConstValue(): "foo" | "bar";
-export declare const constY: number;
+export declare const constY: 1 | 0;
 export declare let letY: number;
 export declare function returnY(): 1 | 0;
$ git add .
$ rm src/a.ts # Simulate using d.ts files externally or via project references
$ tsc
$ git diff src/*.d.ts
diff --git a/src/b.d.ts b/src/b.d.ts
index a79657f..a561a4d 100644
--- a/src/b.d.ts
+++ b/src/b.d.ts
@@ -1,8 +1,8 @@
 export declare const constFromConst: "foo" | "bar";
-export declare let letFromConst: string;
+export declare let letFromConst: "foo" | "bar";
 export declare const constFromLet: string;
 export declare let letFromLet: string;
 export declare function returnConstValue(): "foo" | "bar";
-export declare const constY: 1 | 0;
-export declare let letY: number;
-export declare function returnY(): 1 | 0;
+export declare const constY: 0 | 1;
+export declare let letY: 0 | 1;
+export declare function returnY(): 0 | 1;

Now we're seeing unwidened types in all new places, even worse than the current state of things.

dts-emit-widened-unwidened-examples's People

Contributors

jakebailey avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.