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

allow type 'unsafe' way to doing es6 style imports #6371

Closed
pdeva opened this issue Jan 6, 2016 · 8 comments
Closed

allow type 'unsafe' way to doing es6 style imports #6371

pdeva opened this issue Jan 6, 2016 · 8 comments
Labels
Duplicate An existing issue was already created Suggestion An idea for TypeScript

Comments

@pdeva
Copy link

pdeva commented Jan 6, 2016

Currently if have an import of a library which doesnt have any type definition, like this:

import {A} from 'randomLib';

Typescript will mark an error saying it cant find randomLib anywhere.
We need some way of telling typescript to suppress the error for this particular import.

@DanielRosenwasser
Copy link
Member

I think the solutions and discussion in #2709 covers this scenario.

@DanielRosenwasser
Copy link
Member

Though, the way you should be fixing this is by declaring the module itself:

declare module "randomLib" {
    export let A: any;
}

@pdeva
Copy link
Author

pdeva commented Jan 6, 2016

this is not feasible for large projects.

now for every library we want to use we have to manually create the
typedefs.

kinda defeats the whole 'superset of JavaScript' message.

On Tuesday, January 5, 2016, Daniel Rosenwasser notifications@github.com
wrote:

Though, the way you should be fixing this is by declaring the module
itself:

declare module "randomLib" {
export let A: any;
}


Reply to this email directly or view it on GitHub
#6371 (comment)
.

Prashant

@DanielRosenwasser
Copy link
Member

I agree, this is extremely frustrating for people who are migrating.

Tangentially, what libraries are you trying to use that don't have typings? Just curious.

@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript In Discussion Not yet reached consensus labels Jan 6, 2016
@RyanCavanaugh
Copy link
Member

This came up during the migrate-a-thon as well. The long tail of libraries is surprisingly long.

@ivogabe
Copy link
Contributor

ivogabe commented Jan 6, 2016

I don't think #2709 wouldn't be the best fix for this issue. When you've got typings for a library later on, you would need to remove : any from all your files. Declaring a weak version of the library would make it easier to migrate later, but it's too much work to create it. I think an easy way to create declare a module, without saying anything of it's content, would be the best solution. I'm thinking on something like this:

declare module "foo";
declare module "bar";

After declaring these modules in a .d.ts file, you can use these modules like you would expect. All kinds of import statements are allowed (legacy, named and default imports) and you won't get type errors. What does everyone think of this?

@pdeva
Copy link
Author

pdeva commented Jan 7, 2016

+1 to @ivogabe

@mhegazy
Copy link
Contributor

mhegazy commented Jan 25, 2016

closing in favor of #6615

@mhegazy mhegazy closed this as completed Jan 25, 2016
@mhegazy mhegazy added Duplicate An existing issue was already created and removed In Discussion Not yet reached consensus labels Jan 25, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

5 participants