TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

Problem sharing TS code files between different Visual Studio projects

Open KoenT-X opened this issue 10 years ago • 7 comments

I've been trying to make 2 Visual Studio 2015 CE web app projects share the same TypeScript file, but could not find a way to do this. I am using the AMD module system with require.

While coding VS seems to be fine with the require("......") statement for the common code file. However, when running, I get an exception from require.

I have more details on the general problem in this SO post: http://stackoverflow.com/questions/35506086/using-typescript-files-in-different-web-apps-with-require-amd

and the repository with a self-contained example that reproduces the problem can be found here: https://bitbucket.org/KoenT_IM/typescripttests

Just build and run the project under Applications/CodeSharingApp1 to reproduce this.

Perhaps the fact that the relative path "climbs out" of the project path to reference the common TS file, is what causes the problem. But then I'm not sure how to share a folder with common TS code files between different projects...

KoenT-X avatar Feb 19 '16 15:02 KoenT-X

what version of TS are you using?

mhegazy avatar Feb 19 '16 18:02 mhegazy

I'm using TypeScript 1.7.6 (in VS2015 CE).

KoenT-X avatar Feb 22 '16 15:02 KoenT-X

hi, I have the same problem. Both vscode and vs2015 can't handle shared files in multipy projects. For example, I have files:

/a/a.ts                ->    import {x} from "../shared/x"
/a/tsconfig.json
/b/b.ts                ->    import {x} from "../shared/x"
/b/tsconfig.json
/x/x.ts                ->    export var x = 1;

The "Find All Reference" doesn't find 'x' in both a.ts and b.ts

heroboy avatar May 10 '16 02:05 heroboy

The "Find All Reference" doesn't find 'x' in both a.ts and b.ts

@heroboy, looks like this is a diffrent issue. this is fixed in https://github.com/Microsoft/TypeScript/pull/7353

mhegazy avatar May 11 '16 21:05 mhegazy

@KoenT-IM consider specifing a require configuration (http://requirejs.org/docs/api.html#config) to map the location of your shared module.

the other option, is to drop all your modules into a single output location, and use baseURL (a TS 2.0 feature, available now in typescript@next).

so your sources would look like:

projectA\
    a.ts     => `import foo from "b"`
projectB\
    b.ts   

with tsconfig.json as:

{
    "compilerOptions": {
        "baseURL" : "./out",
        "outDir": "./out"
    }
}

see https://github.com/Microsoft/TypeScript-Handbook/blob/release-2.0/pages/Module%20Resolution.md#base-url for more details.

mhegazy avatar May 11 '16 21:05 mhegazy

the original issue seems to be addressed. please reopen if this is not the case.

mhegazy avatar Jun 06 '16 20:06 mhegazy

Thanks mhegazy. Will verify and come back to this if needed soon (working towards a release now).

KoenT-X avatar Jun 07 '16 07:06 KoenT-X