Comments (5)
I'm not 100% convinced this is safe. @dragomirtitian , thoughts?
from typescript.
We generally don't look up any symbols beyond the current expression. So Foo.A
could really be anything not necessarily an enum. Looking up the symbol in the same file is feasible, but what would only allow you to write this if the enum is in the same file. And looking at symbols across files goes against one of the design goals of isolated declarations (allowing single file .d.ts emit)
So we could do it in some cases. Our though process is that generally we should be consistent. It would be a bit strange for this to work only within a file.
I think there is a case to be made that we could allow more of these in isolated declarations if there is demand for it. But I think this limitation should stay for v1 of this feature.
from typescript.
That's fair. An idea I haven't put much thought into is to emit something like
export enum Foo {
A = 1,
B = 2,
}
export declare const x: typeof Foo.A;
export declare const y: readonly [typeof Foo.A];
when the subject of typeof
is a valid expression. At least that would allow deferring any potential errors until later, e.g. with "skipLibCheck: false".
I think a hard case might be something like:
export enum Foo {
A = 1,
B = 2,
}
export const x = {
[Foo.A]: 1,
[Foo.B]: 2,
} as const;
since you'd have to maybe emit something like
export enum Foo {
A = 1,
B = 2,
}
export declare const x: {
readonly [K in typeof Foo.A]: 1;
} & {
readonly [K in typeof Foo.B]: 2;
}
which I'd be ok with, but perhaps beyond the level of complexity you'd want to implement in tsc
from typescript.
For computed properties we already allow this and error in TS if the type is not a late bindable computed property (ie it's not a property that can be a computed key and would have t be turned into a string index)
For other positions, we did debate doing typeof Identifier
. It's not totally off the table as a possible future improvement, but it is not always 100% accurate so there would have to be places where const x = y
is an error because const x: typeof y
is not actually the correct type.
enum E { A = 1, }
let x = E.A;
const y = E.A // equivalent to typeof E.A
const s = Symbol();
const z = s // not equivalent to typeof s
This is a class of inferences we called optimistic inferences. We did however rule them out for the time being as being too confusing to explain why this would fail sometimes.
from typescript.
Subtle, didn't realize unique symbols had such unique behavior 🙂
from typescript.
Related Issues (20)
- tsc --init update 2024 HOT 5
- [transpileDeclaration API][5.5] Type containing enum values is incorrectly emitted HOT 3
- 5.5 Beta - Error assigning const string to enum from another file HOT 3
- `export default` generates JavaScript and declaration file incompatible HOT 3
- Issues with `isolatedDeclarations` and the associated fixes in editor HOT 5
- Incremental Builds are not Reliable v5.4.5 HOT 2
- Design Meeting Notes, 5/3/2024 HOT 1
- [transpileDeclaration API][5.5] Type-only import is missing when type is used as arrow function argument HOT 3
- Error on types when using multiple conditional properties HOT 3
- Compiler Option to monitor external dependencies
- Extract interface metadata for runtime HOT 2
- Enum allows numeric keys with leading 0s HOT 5
- Various bugs with class expressions and JavaScript decorators (code run twice, internal compiler crash) HOT 1
- JSDoc unexpected type error when spreading array containing different shapes of same type HOT 3
- Selecting suggestion of string completion deletes everything up to end of line, if no ending quote is present
- Hitting TS Limits: "Max Call Stack Size Exceeded" HOT 3
- [NewErrors] 5.5.0-dev.20240505 vs 5.4.5 HOT 52
- Error in Index Signature Assignment HOT 3
- [ServerErrors][TypeScript] 5.5.0-dev.20240505 HOT 15
- [ServerErrors][JavaScript] 5.5.0-dev.20240505 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.