GithubHelp home page GithubHelp logo

[isolatedDeclarations] Add a syntactic form of computed property name which is always emitted as a computed property name about typescript HOT 5 OPEN

weswigham avatar weswigham commented on June 27, 2024 1
[isolatedDeclarations] Add a syntactic form of computed property name which is always emitted as a computed property name

from typescript.

Comments (5)

weswigham avatar weswigham commented on June 27, 2024 1

I guess what I don’t understand is, if you’re already capable of doing this check for an arbitrary expression in the something position, what does the extra syntax buy you? It just feels like noise then.

Given

// @filename: node_modules/mod/index.ts
export const something = Math.random() ? 1 : 2;

then

import {something} from "mod";
export const a = {[something]: 1};

has no errors, while

import {something} from "mod";
export const a = {[something satisfies keyof]: 1};

issues an error on something: A satisfies keyof computed property name must be exactly a single string, number, or unique symbol literal type.

and

import {something} from "mod";
export const a = {[something]: 1};

emits

export const a: {[something: number]: number};

in accordance with the type of the resolved something, but

import {something} from "mod";
export const a = {[something satisfies keyof]: 1};

always emits, even if something cannot be resolved:

import {something} from "mod";
export const a: {[something]: number};

from typescript.

weswigham avatar weswigham commented on June 27, 2024 1

It's basically a way to pull the error the declaration file would get from preserving the computed property name forward into the input file.

from typescript.

fatcerberus avatar fatcerberus commented on June 27, 2024

… and issue an error on something satisfies keyof if something isn't exactly a single unique symbol, string literal, or number literal type (as is valid in the type position computed property name).

I guess what I don’t understand is, if you’re already capable of doing this check for an arbitrary expression in the something position, what does the extra syntax buy you? It just feels like noise then.

from typescript.

fatcerberus avatar fatcerberus commented on June 27, 2024

Ah, so it's basically a syntactic hint not to widen it to an index signature, we always want it to show up as a computed property in types. satisfies keyof being that hint feels really awkward and non-intuitive, but that's strictly in 🚲 🏠 territory which it's probably too early for.

from typescript.

AlCalzone avatar AlCalzone commented on June 27, 2024

Since Symbol.iterator is called out here, I just wanted to throw Symbol.asyncIterator into the ring because I didn't see it mentioned anywhere else and also produces an error currently.

from typescript.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.