microsoft / microsoft/TypeScript
[Feature Request] NoneEmptyRecord
Open
Nobody has claimed this yet.
Awaiting More Feedback
Suggestion
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
Suggestion
add empty check on record
🔍 Search Terms
empty record
✅ Viability Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
⭐ Suggestion
📃 Motivating Example
type A = NoneEmptyRecord<string, any>;
const a1: A = {}; // error
const a2: A = { a: 1 }; // ok
function fn(arg: A) {}
fn({}) // expect error
fn({ a: 1 }) // ok
type B = NoneEmptyRecord<string, NoneEmptyRecord<string, any>>;
const b1: B = {} // error
const b2: B = { a: {} } // error
const b3: B = { a: { b: 1 } } // ok
function fn(arg: B) {}
fn({}) // error
fn({ a: {} }) // error
fn({ a: { b: a } }) // ok
💻 Use Cases
when writing a js "struct" define complie to wgsl struct
const wgslStructDefine = {
ambient: 'vec3_f32',
lightCount: 'u32',
list: 'f32',
substruct: {
a: 'f32',
b: 'f32',
},
lights: [
{
position: 'vec3_f32',
range: 'f32',
color: 'vec3_f32',
intensity: 'f32',
},
],
};
// then compile to wgsl struct
const output = `
struct Asubstruct {
a: f32,
b: f32,
};
struct Alights {
position: vec3<f32>,
range: f32,
color: vec3<f32>,
intensity: f32,
};
struct A {
ambient: vec3<f32>,
lightCount: f32,
substruct: Asubstruct,
lights: array<Alights>
}
`;
it will be error with empty wgsl struct, althought it can be check in js, but it will be nicer with NoneEmptyRecord during static check.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No source file or test is named; start with the motivating TypeScript examples and the linked TypeScript design goals. A complete investigation would need to establish whether the requested static checks fit the project constraints and define expected results for each example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100