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

Not to remove unused import module ? #21114

Closed
zD98 opened this issue Jan 10, 2018 · 6 comments
Closed

Not to remove unused import module ? #21114

zD98 opened this issue Jan 10, 2018 · 6 comments
Labels
Fixed A PR has been merged for this issue

Comments

@zD98
Copy link

zD98 commented Jan 10, 2018

TypeScript Version: 2.4.1

Code

// tsconfig.json
{
...
"jsx": "preserve",
...
}
// my preact Component
import {h, Component} from 'preact'
class C extends Component<any, any> {
    render(){
    // ...
    }
}
// after compiled
import { Component } from 'preact'

So it will throw an error, such as "h is not defined"

Expected behavior:

// after compiled
import {h, Component } from 'preact'

Actual behavior:

// after compiled
import {Component} from 'preact' 

Related:

@zD98 zD98 changed the title Not to remove unused import ? Not to remove unused import module ? Jan 10, 2018
@zD98
Copy link
Author

zD98 commented Jan 10, 2018

Now I have to add a hard code.

import {h as PreactH , Component} from 'preact'
const h = PreactH

@mhegazy
Copy link
Contributor

mhegazy commented Jan 10, 2018

Assuming you set --jsxFactory h, we should always preserve this import, and make sure h is defined in the output if you ever use a JSX element in this file.

@mhegazy mhegazy added the Bug A bug in TypeScript label Jan 10, 2018
@mhegazy mhegazy added this to the TypeScript 2.8 milestone Jan 10, 2018
@zD98
Copy link
Author

zD98 commented Jan 11, 2018

@mhegazy thanks for the quick reply!
--jsxFactory h is ok in a pure TS + Preact project. However, my project has React and Preact frameworks.

@mhegazy
Copy link
Contributor

mhegazy commented Jan 11, 2018

I do not think we can keep both.. the compiler has no way of knowing which one is used otherwise.

@mhegazy mhegazy added Working as Intended The behavior described is the intended behavior; this is not a bug and removed Bug A bug in TypeScript labels Jan 17, 2018
@mhegazy mhegazy removed this from the TypeScript 2.8 milestone Jan 17, 2018
@mhegazy
Copy link
Contributor

mhegazy commented Jan 17, 2018

I was wrong about my original analysis. h is preserved if it is in the --jsxFactory. so this is not a bug. having both React.createElement and h in the same project is tracked by #15386 and #18131

@typescript-bot
Copy link
Collaborator

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@mhegazy mhegazy added Fixed A PR has been merged for this issue and removed Working as Intended The behavior described is the intended behavior; this is not a bug labels Feb 27, 2018
@mhegazy mhegazy added this to the TypeScript 2.8 milestone Feb 27, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

4 participants