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

Error on export default of type: issue https://github.com/microsoft/TypeScript/issues/55087 #55097

Merged
merged 10 commits into from
Nov 20, 2023

Conversation

EliLichtblau
Copy link
Contributor

@EliLichtblau EliLichtblau commented Jul 21, 2023

Fixes: #55087
This changes the behavior of TS to the specified behavior in issue.

Export default of types become errors - i.e

type foo = 3
export default foo

This is because if it does not error - typescript emits invalid code.

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Jul 21, 2023
@typescript-bot
Copy link
Collaborator

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

@EliLichtblau
Copy link
Contributor Author

@microsoft-github-policy-service agree

@EliLichtblau
Copy link
Contributor Author

Fixes: #55087

  • trying to trigger link issue

@fatcerberus
Copy link

FWIW I think it's okay to default-export types in general, as long as they only have a typespace meaning--the problem is when you default-export something that has a valuespace meaning (like a class) which has been imported via import type.

@EliLichtblau
Copy link
Contributor Author

If this is the only condition - I think you can just convert

 if (!isIllegalExportDefaultInCJS && !(node.flags & NodeFlags.Ambient) && compilerOptions.verbatimModuleSyntax && getTypeOnlyAliasDeclaration(sym, SymbolFlags.Value)) {

to

if (!(node.flags & NodeFlags.Ambient) && getTypeOnlyAliasDeclaration(sym, SymbolFlags.Value)) {

the reason I find this a little awkward is checking with ts-fork-typechecker but emitting with ts loader transpileOnly is pretty common and you can pass the typechecking stage and still emit invalid code as the following code:

ts.transpileModule(`
import {type Node} from "typescript"
export default Node
`, {})

will give you

export default Node

even though Node is an interface. I can understand why you (the TS team) would say this is improper use and shouldn't be supported though.

With that said, my take is:

  • There should be a flag which disables all export default of things (need a better word here sorry) imported in a typeOnly context as this can emit invalid code with transpileModule calls
  • The check on export default of import types should not live behind the verbatim module syntax flag and should be default behavior

But I will implement whatever you think is best

The best solution IMO is to not change compile time behavior at all and for emit to just work but based on your comments in the issue I am unsure if this is possible. I know less than little about the emit phase so I don't have any idea here.

Copy link
Member

@andrewbranch andrewbranch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the expected behavior is

  • an export default of a type-only import never emits anything
  • it’s an error only in isolatedModule (ts1205)

@andrewbranch
Copy link
Member

andrewbranch commented Nov 13, 2023

Fixed the checker behavior, still need to fix the emit. (Disregard the review request, I jumped the gun.)

@andrewbranch
Copy link
Member

Ok, ready.

Copy link
Member

@jakebailey jakebailey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but should get the extended test run.

@@ -41,7 +41,6 @@ exports.A = A;
//// [b.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = types;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeppp

@jakebailey
Copy link
Member

@typescript-bot test top200
@typescript-bot user test this
@typescript-bot run dt

@typescript-bot perf test this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Nov 13, 2023

Heya @jakebailey, I've started to run the parallelized Definitely Typed test suite on this PR at 12f9ae6. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Nov 13, 2023

Heya @jakebailey, I've started to run the diff-based top-repos suite on this PR at 12f9ae6. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Nov 13, 2023

Heya @jakebailey, I've started to run the regular perf test suite on this PR at 12f9ae6. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Nov 13, 2023

Heya @jakebailey, I've started to run the diff-based user code test suite on this PR at 12f9ae6. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

@jakebailey Here are the results of running the user test suite comparing main and refs/pull/55097/merge:

There were infrastructure failures potentially unrelated to your change:

  • 2 instances of "Package install failed"

Otherwise...

Something interesting changed - please have a look.

Details

puppeteer

packages/browsers/test/src/tsconfig.json

@typescript-bot
Copy link
Collaborator

@jakebailey
The results of the perf run you requested are in!

Here they are:

Compiler

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
Angular - node (v18.15.0, x64)
Memory used 295,141k (± 0.02%) 295,178k (± 0.02%) ~ 295,102k 295,242k p=0.336 n=6
Parse Time 2.62s (± 0.67%) 2.62s (± 0.52%) ~ 2.60s 2.64s p=0.867 n=6
Bind Time 0.84s (± 1.30%) 0.83s (± 0.49%) ~ 0.83s 0.84s p=0.178 n=6
Check Time 8.07s (± 0.17%) 8.04s (± 0.26%) ~ 8.01s 8.06s p=0.056 n=6
Emit Time 7.07s (± 0.31%) 7.10s (± 0.65%) ~ 7.06s 7.18s p=0.746 n=6
Total Time 18.61s (± 0.04%) 18.60s (± 0.25%) ~ 18.54s 18.68s p=0.328 n=6
Compiler-Unions - node (v18.15.0, x64)
Memory used 193,619k (± 1.65%) 190,691k (± 0.01%) ~ 190,661k 190,718k p=0.128 n=6
Parse Time 1.35s (± 0.61%) 1.35s (± 0.90%) ~ 1.35s 1.38s p=0.218 n=6
Bind Time 0.73s (± 0.00%) 0.73s (± 0.56%) ~ 0.73s 0.74s p=0.405 n=6
Check Time 9.13s (± 0.43%) 9.18s (± 0.36%) +0.05s (+ 0.49%) 9.14s 9.22s p=0.044 n=6
Emit Time 2.62s (± 0.48%) 2.62s (± 0.59%) ~ 2.60s 2.64s p=1.000 n=6
Total Time 13.83s (± 0.31%) 13.88s (± 0.16%) ~ 13.85s 13.91s p=0.053 n=6
Monaco - node (v18.15.0, x64)
Memory used 347,343k (± 0.01%) 347,372k (± 0.01%) ~ 347,347k 347,408k p=0.054 n=6
Parse Time 2.46s (± 0.49%) 2.46s (± 0.72%) ~ 2.43s 2.48s p=0.935 n=6
Bind Time 0.94s (± 0.67%) 0.94s (± 0.43%) ~ 0.94s 0.95s p=0.673 n=6
Check Time 6.92s (± 0.66%) 6.93s (± 0.27%) ~ 6.90s 6.95s p=0.222 n=6
Emit Time 4.05s (± 0.34%) 4.06s (± 0.61%) ~ 4.04s 4.09s p=0.745 n=6
Total Time 14.37s (± 0.36%) 14.39s (± 0.25%) ~ 14.36s 14.46s p=0.226 n=6
TFS - node (v18.15.0, x64)
Memory used 302,592k (± 0.00%) 302,606k (± 0.01%) ~ 302,583k 302,674k p=0.468 n=6
Parse Time 1.99s (± 0.99%) 1.99s (± 0.74%) ~ 1.97s 2.01s p=0.934 n=6
Bind Time 1.01s (± 1.02%) 1.01s (± 0.74%) ~ 1.00s 1.02s p=0.437 n=6
Check Time 6.25s (± 0.41%) 6.25s (± 0.36%) ~ 6.22s 6.28s p=0.808 n=6
Emit Time 3.58s (± 0.62%) 3.58s (± 0.57%) ~ 3.56s 3.61s p=0.871 n=6
Total Time 12.83s (± 0.37%) 12.84s (± 0.33%) ~ 12.80s 12.92s p=1.000 n=6
material-ui - node (v18.15.0, x64)
Memory used 470,568k (± 0.01%) 470,574k (± 0.00%) ~ 470,553k 470,592k p=0.689 n=6
Parse Time 2.56s (± 0.68%) 2.57s (± 0.78%) ~ 2.54s 2.60s p=0.567 n=6
Bind Time 0.98s (± 1.23%) 0.99s (± 0.52%) ~ 0.99s 1.00s p=0.142 n=6
Check Time 16.68s (± 0.40%) 16.65s (± 0.55%) ~ 16.58s 16.83s p=0.334 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 20.23s (± 0.26%) 20.21s (± 0.46%) ~ 20.14s 20.40s p=0.228 n=6
xstate - node (v18.15.0, x64)
Memory used 512,837k (± 0.01%) 512,827k (± 0.02%) ~ 512,743k 512,956k p=0.810 n=6
Parse Time 3.27s (± 0.23%) 3.27s (± 0.16%) ~ 3.27s 3.28s p=0.784 n=6
Bind Time 1.54s (± 0.35%) 1.54s (± 0.82%) ~ 1.53s 1.56s p=0.357 n=6
Check Time 2.86s (± 0.68%) 2.86s (± 0.69%) ~ 2.85s 2.90s p=0.747 n=6
Emit Time 0.08s (± 0.00%) 0.08s (± 0.00%) ~ 0.08s 0.08s p=1.000 n=6
Total Time 7.75s (± 0.23%) 7.75s (± 0.21%) ~ 7.73s 7.78s p=1.000 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • Angular - node (v18.15.0, x64)
  • Compiler-Unions - node (v18.15.0, x64)
  • Monaco - node (v18.15.0, x64)
  • TFS - node (v18.15.0, x64)
  • material-ui - node (v18.15.0, x64)
  • xstate - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

tsserver

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
Compiler-UnionsTSServer - node (v18.15.0, x64)
Req 1 - updateOpen 2,377ms (± 1.04%) 2,372ms (± 1.05%) ~ 2,329ms 2,392ms p=0.809 n=6
Req 2 - geterr 5,367ms (± 1.43%) 5,364ms (± 1.64%) ~ 5,285ms 5,476ms p=0.748 n=6
Req 3 - references 328ms (± 1.39%) 326ms (± 0.53%) ~ 323ms 328ms p=0.935 n=6
Req 4 - navto 277ms (± 1.05%) 277ms (± 0.98%) ~ 273ms 279ms p=0.867 n=6
Req 5 - completionInfo count 1,356 (± 0.00%) 1,356 (± 0.00%) ~ 1,356 1,356 p=1.000 n=6
Req 5 - completionInfo 83ms (± 7.99%) 81ms (± 8.64%) ~ 75ms 90ms p=0.563 n=6
CompilerTSServer - node (v18.15.0, x64)
Req 1 - updateOpen 2,499ms (± 0.66%) 2,502ms (± 0.72%) ~ 2,473ms 2,527ms p=0.471 n=6
Req 2 - geterr 4,056ms (± 1.55%) 4,082ms (± 1.83%) ~ 4,027ms 4,178ms p=0.469 n=6
Req 3 - references 343ms (± 1.23%) 340ms (± 1.70%) ~ 333ms 345ms p=0.565 n=6
Req 4 - navto 283ms (± 0.37%) 282ms (± 0.32%) ~ 281ms 283ms p=0.273 n=6
Req 5 - completionInfo count 1,518 (± 0.00%) 1,518 (± 0.00%) ~ 1,518 1,518 p=1.000 n=6
Req 5 - completionInfo 88ms (± 5.56%) 86ms (± 6.77%) ~ 78ms 90ms p=0.390 n=6
xstateTSServer - node (v18.15.0, x64)
Req 1 - updateOpen 2,592ms (± 0.40%) 2,589ms (± 0.46%) ~ 2,571ms 2,604ms p=0.809 n=6
Req 2 - geterr 1,720ms (± 2.03%) 1,718ms (± 2.54%) ~ 1,674ms 1,766ms p=0.873 n=6
Req 3 - references 109ms (± 7.35%) 111ms (± 9.02%) ~ 101ms 122ms p=1.000 n=6
Req 4 - navto 366ms (± 0.52%) 368ms (± 1.27%) ~ 365ms 377ms p=0.564 n=6
Req 5 - completionInfo count 2,073 (± 0.00%) 2,073 (± 0.00%) ~ 2,073 2,073 p=1.000 n=6
Req 5 - completionInfo 311ms (± 2.08%) 308ms (± 2.50%) ~ 299ms 318ms p=0.686 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • CompilerTSServer - node (v18.15.0, x64)
  • Compiler-UnionsTSServer - node (v18.15.0, x64)
  • xstateTSServer - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Startup

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
tsc-startup - node (v18.15.0, x64)
Execution time 152.71ms (± 0.18%) 152.72ms (± 0.19%) ~ 151.55ms 155.92ms p=0.960 n=600
tsserver-startup - node (v18.15.0, x64)
Execution time 227.96ms (± 0.16%) 227.67ms (± 0.15%) -0.29ms (- 0.13%) 226.32ms 232.50ms p=0.000 n=600
tsserverlibrary-startup - node (v18.15.0, x64)
Execution time 229.56ms (± 0.17%) 229.53ms (± 0.16%) ~ 227.86ms 234.24ms p=0.428 n=600
typescript-startup - node (v18.15.0, x64)
Execution time 229.30ms (± 0.16%) 229.37ms (± 0.16%) +0.06ms (+ 0.03%) 227.87ms 236.46ms p=0.046 n=600
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • tsc-startup - node (v18.15.0, x64)
  • tsserver-startup - node (v18.15.0, x64)
  • tsserverlibrary-startup - node (v18.15.0, x64)
  • typescript-startup - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Developer Information:

Download Benchmarks

@typescript-bot
Copy link
Collaborator

Hey @jakebailey, the results of running the DT tests are ready.
Everything looks the same!
You can check the log here.

@typescript-bot
Copy link
Collaborator

@jakebailey Here are the results of running the top-repos suite comparing main and refs/pull/55097/merge:

Something interesting changed - please have a look.

Details

heyxyz/hey

apps/prerender/tsconfig.json

  • error TS1292: 'Profile' resolves to a type and must be marked type-only in this file before re-exporting when 'isolatedModules' is enabled. Consider using 'export type { Profile as default }'.

microsoft/playwright

5 of 15 projects failed to build with the old tsc and were ignored

packages/recorder/tsconfig.json

@andrewbranch
Copy link
Member

These errors from the top repos look possibly wrong, especially the playwright one. Need to take a closer look.

@andrewbranch
Copy link
Member

@typescript-bot test top200

@typescript-bot
Copy link
Collaborator

typescript-bot commented Nov 17, 2023

Heya @andrewbranch, I've started to run the diff-based top-repos suite on this PR at 7b2dee6. You can monitor the build here.

Update: The results are in!

@jakebailey
Copy link
Member

You can ignore that playwright one, that is currently happening on every PR and we just haven't looked at why.

@andrewbranch
Copy link
Member

Huh? The playwright one is clearly caused by this and fixed in the latest commit.

@jakebailey
Copy link
Member

Apologies, I mixed up the "P" libraries and confused playwright for puppeteer (which you can see on other PRs like #56429 (comment)). Ignore me!

@typescript-bot
Copy link
Collaborator

@andrewbranch Here are the results of running the top-repos suite comparing main and refs/pull/55097/merge:

Everything looks good!

@andrewbranch andrewbranch merged commit 9063d7b into microsoft:main Nov 20, 2023
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Export default of type emits invalid code
5 participants