Comments (8)
I didn't say I'm happy I fixed this, did I?
from typescript.
At that point, couldn't you import './a.base'
? There would be no a.base.platformX.ts
so it would eventually resolve to just a.base.ts
.
from typescript.
accidentally-ish one of my recent PRs fixes this: #58668 , maybe @jakebailey could create a TS build of that PR so you could fully confirm that
from typescript.
@Andarist And you wanted to make this an error across the board... tsk tsk 😉
from typescript.
I really wonder why @Aarononomous is doing this in his code though. What's the reason behind importing a side-effectful .ts
without enabling allowImportingTsExtensions
? 🤔
from typescript.
I really wonder why @Aarononomous is doing this in his code though. What's the reason behind importing a side-effectful
.ts
without enablingallowImportingTsExtensions
? 🤔
I'm working in a multitenant codebase. We put platform-specific code in *.platformName.ts
files, adding the platform name as an extension. Then we have a webpack resolver configured to look for platform files preferentially,
resolve: {
extensions: [
...
`.${CONFIG.platform}.ts`,
`.${CONFIG.platform}.tsx`,
'.ts',
'.tsx',
...
so that when we build for, say, platformX and see import './a'
, we first look for a file at ./a.platformX.ts
, then ./a.ts
. This allows us to write all of our platform-specific code without runtime tests or compiler macros or whatever, neatly encapsulated in its own file.
So not only do we not want to allow ts extensions, we can't! Otherwise our whole multitenant resolver behavior falls apart.
The exception to this is in the multitenant files themselves, where we do sometimes want to import common code from the extensionless base files, e.g.
a.platformX.ts
// @ts-expect-error
// We need the full filename with extension here: otherwise there's a circular import
import { module as baseModule } from './a.ts';
// do something with baseModule...
export const module;
The 'allowImportingTsExtensions'
error is expected when we import with a full filename. It's just when we only import for side effects from the base file that we see this inconsistency in --watch
mode.
So the code example above is really more like
a.ts
window.__CONFIG__ = { ... };
a.platformX.ts
import './a.ts';
window.__CONFIG__.platformX = { ... };
from typescript.
The use case makes sense but I think you could introduce some other convention for those base modules to avoid this problem altogether.
from typescript.
@Andarist, what do you suggest?
If I put my side-effectful code in, say, a.base.ts, I'd still be calling it in a.ts, a.platformX.ts, etc. with
import 'a.base.ts';
from typescript.
Related Issues (20)
- spread operator infer to wrong type with method override and generic HOT 6
- Intellisense is slow and some things don't work HOT 4
- Constructor cannot access own protected instance when typed as union HOT 2
- This comparison appears to be unintentional because the types 'U[K]' and 'T[K]' have no overlap.ts(2367) HOT 3
- [isolatedDeclarations] Optional parameter in arrow function typed as imported generic type gets emitted as `any`
- Easier use of indexed access types on nullable/optional types HOT 2
- Narrow conditional type HOT 1
- Error for path not found when ended with asterisk
- `tryGetPerformanceHooks` throws on Stackblitz with ts 5.5.3 HOT 3
- Avoid providing promise methods as completions at return positions in non-async functions
- Consider disallowing `in` operator use with arbitrary key operands on closed types for which the keys are known HOT 2
- Convert to ESM uses template strings instead of string literals HOT 1
- Running type checker produces js out of memory error HOT 2
- Callback argument type not inferred for union of interfaces HOT 1
- Como Hackear Instagram 2024 Hackear Instagram Metodos Atualizados #221857
- [transpileDeclaration API] ts.transpileDeclaration always returns empty sourceMapText
- Incorrect Error Message: "Cannot assign to 'name' because it is a constant" Instead of "Identifier 'name' is not defined" for Undefined Identifier Assignment HOT 2
- Generic with extends yields to different type than directly specifying it HOT 5
- Instantiation expressions don't reject incompatible signatures in situations with mixed call and construct signatures HOT 1
- Parameters of overridden methods are made implicit any when using JSDoc `@override` HOT 13
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typescript.